Common operations

Here is a first list of useful ressources to manage Django

Activate virtual env

To use Django command line, activate the virtual environement

usr1@server:~/myprojectdir$ source myprojectenv/bin/activate

The prompt is changed as follows

(myprojectenv) usr1@server:~/myprojectdir$

Execute the build of the project

Once the configuration has been done execute

(myprojectenv) usr1@server:~/myprojectdir$ python3 manage.py migrate

Restart Gunicorn to apply the changes

(myprojectenv) usr1@server:~/myprojectdir$ sudo systemctl restart gunicorn

Add pages to Django app

Copy the *.html page into doc1/templates directory.

manage.py
myproject
myprojectenv
static
demo1
├── admin.py
├── apps.py
├── migration
├── models.py
├── tests.py
├── views.py
├── templates
    ├── demo1
        ├── index.html
        ├── new_page.html

Edit new_page.html to add the line {% load static %} at the begining of the file

{% load static %}
<!DOCTYPE html>
.
.

Edit demo1/urls.py to declare the new page

# config/urls.py

from django.urls import path, include # Import this function
from . import views

app_name = "demo1"

urlpatterns = [
    # Main app
    path('', views.index, name="index"),
    path('index.html', views.index, name="index"),
    path('1_how_to_sphinx.html', views.how_to_sphinx, name="How to sphinx"),
]

Edit demo1/views.py to create the view for the new page

from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.template import loader
from django.urls import reverse
from django.views import generic

def index(request):
    return render (request, 'demo1/index.html', {})

def how_to_sphinx(request):
    return render (request, 'demo1/1_how_to_sphinx.html', {})