Search code examples
djangopython-sphinxrestructuredtextdocstring

How to format Django views' docstring


I use simple views in my project, and now my project begin to be bigger, I'm writing a sphinx doc and use objects docstrings with sphinx.ext.autodoc for inclusion.

My trouble is: How to greatly format view's docstring ?

  • Document GET/POST and more behavior.
  • Template(s) used
  • Context content

For example, I'm using:

def my_view(request):
    """
    Do something depending of HTTP method.

    In GET: Returns a page
    IN POST: Make something and redirect

    GET parameters:
    GET['next'] : URL to redirect to after submit form

    POST parameters:
    POST['action'] : Action
    """

I'm self-asking if there is a better way to do this ? Is there any consensus about it ?


Solution

  • A few examples you can find here: https://docs.djangoproject.com/en/1.8/ref/contrib/admin/admindocs/