A. Pipreqs module generates document dependencies
Projects often install many modules, in order to better portability, we can use pipreqs module generates dependencies document.
1.1 Installation pipreqs module
pip install pipreqs
Corresponding to the path for the 1.2 generation
Switch to the root directory of the project, or projects to a path:
D:\youkutest\luffyapi>pipreqs ./ --encoding=utf8
The above project called luffyapi, --encoding = utf8 behind the increase is to prevent problems due to coding error, plus recommendations.
1.3 install new environment dependencies
When you copy the entire project to a new environment, simply execute the following command to install dependencies, before pipreqs be installed in the new environment.
pip install -r requriements.txt
Note: This module is sometimes unable to generate all dependent packages, some may need to manually installed.
Two. Coreapi automatically generates the interface documentation
Work in the interface documentation on how to write handwriting is very time-consuming, djangorestframework provides us with a method to automatically generate interface documentation, but which will only generate direct or indirect interface inheritance document view APIView class.
2.1 Installation dependencies
pip install -i https://pypi.douban.com/simple/ coreapi
2.2 Setting the interface document access path
Adding interface documentation path in the overall route,
from rest_framework.documentation Import include_docs_urls the urlpatterns = [ ... path ( ' docs / " , include_docs_urls (title = ' site page title ' )) ]
2.3 defines the location of the document description explains
Documentation string view, view class may be used as 1) a single process, such as
class BookListView (generics.ListAPIView): "" " . returns all book information ." ""
2) a method comprising a plurality of views, the view of the document string class, method defined separately, such as
class BookListCreateView (generics.ListCreateAPIView): "" " GET: returns all book information. POST: New Book. " ""
3) For set Viewset view, the document view of the string class are still closed to open is defined, it is to be used to distinguish the name of action, such as
class BookInfoViewSet (mixins.ListModelMixin, mixins.RetrieveModelMixin, GenericViewSet): "" " List: return the book list data retrieve: return the book details the data latest: returns the latest data of the book read: Modify the amount of reading books ." ""
2.4 Access Interface Documentation Web page
Browser access 127.0.0.1:8000/docs/, you can see the interface documentation automatically generated.
Just two points:
1) View Set ViewSet retrieve the name, called the read document interface site
2) Description of parameters need to be defined in the model options help_text class or classes of sequences of fields, such as:
class Student(models.Model): ... age = models.IntegerField(default=0, verbose_name='年龄', help_text='年龄') ...
or
class StudentSerializer(serializers.ModelSerializer): class Meta: model = Student fields = "__all__" extra_kwargs = { 'age': { 'required': True, 'help_text': '年龄' } }