Difference between revisions of "Django"

From Network Security Wiki
Jump to navigation Jump to search
Line 29: Line 29:
 
These files are:
 
These files are:
  
*The outer mysite/ root directory is just a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.
+
*'''The outer mysite/''' root directory is just a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.
*manage.py: A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin and manage.py.
+
*'''manage.py''': A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin and manage.py.
*The inner mysite/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. mysite.urls).
+
*'''The inner mysite/''' directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. mysite.urls).
*mysite/__init__.py: An empty file that tells Python that this directory should be considered a Python package. If you’re a Python beginner, read more about packages in the official Python docs.
+
*'''mysite/__init__.py''': An empty file that tells Python that this directory should be considered a Python package. If you’re a Python beginner, read more about packages in the official Python docs.
*mysite/settings.py: Settings/configuration for this Django project. Django settings will tell you all about how settings work.
+
*'''mysite/settings.py''': Settings/configuration for this Django project. Django settings will tell you all about how settings work.
*mysite/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.
+
*'''mysite/urls.py''': The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.
*mysite/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGI for more details.
+
*'''mysite/wsgi.py''': An entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGI for more details.

Revision as of 20:26, 12 December 2018


Source: djangoproject.com

Installation:

sudo pip3 install django

Check installed version:

python3 -m django --version


Creating a project

cd  /home/mycode (Do not put code under /var/www)
django-admin startproject mysite 

Avoid using names like django (conflict with Django itself) or test (conflicts with a built-in Python package)

Startproject command will create:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py


These files are:

  • The outer mysite/ root directory is just a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.
  • manage.py: A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin and manage.py.
  • The inner mysite/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. mysite.urls).
  • mysite/__init__.py: An empty file that tells Python that this directory should be considered a Python package. If you’re a Python beginner, read more about packages in the official Python docs.
  • mysite/settings.py: Settings/configuration for this Django project. Django settings will tell you all about how settings work.
  • mysite/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.
  • mysite/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGI for more details.