Project

General

Profile

Django

Helpful information for working with Django.

Pydoc

Pydoc is the Python documentation generator. Unfortunately, it does not work "out of the box" with Django projects because Pydoc imports modules as it creates the help information. When it does so, it lacks the Django framework and generates errors. Pydoc currently (2022) also ships "broken" because it is hard coded to use Python 2.7!

Pydoc for Django Fix

A solution was derived from this page: https://stackoverflow.com/questions/24772805/python-documentation-for-django-views-generic-with-pydoc by changing from cli mode to browser mode.

Create this as a file called my_pydoc.py in the same folder as your manage.py file for the project:

import django
import pydoc
import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'iot_rpi.settings'
django.setup()
#pydoc.cli()
pydoc.browse(9999)

Now, from within your Python virtual environment (remember to use the "source" command!) run this to start your web browser with the documentation:

python -m my_pydoc

You should now be able to access the documentation for your Django project and it's apps - as well as documentation for Python itself.

Pydoc for Python 3.x Programs

Apache Integration

If you run into issues integrating your Django site to be served from Apache for production, this information may help. It is not fully vetted, so some experimentation may be required. This example assumes the Django project is called ADC_server.

# Apache server requires read and write access to these
chmod a+w ~/Documents/django/project/ADC_Server/db.sqlite3
chmod -R a+w ~/Documents/django/project/ADC_Server/sent_emails/
sudo chgrp -R www-data /home/capstone
chmod g+rwxs ~/Documents/django/project/ADC_Server/

# add capstone to the adm group so you can see the Apache logs for troubleshooting
sudo usermod -aG adm capstone

Pylint

Per their site, "Pylint is a source-code, bug and quality checker for the Python programming language".

Pylint has a command line argument to support Django! This is mentioned on this page: https://pylint.readthedocs.io/en/latest/user_guide/ide-integration.html