Write the first Django app, part one--Create a project
Let's learn by example.
Through this guided tour, we will teach you step-by-step to create a simple voting system.
The system is divided into two parts:
1. A public page that allows people to vote and view the results of a poll.
2. An admin page lets you add, modify, and delete votes.
We assume that you have the Django installed. You can run the Python compiler and enter the import Django to test that Django is installed. If the command runs successfully, there is no error, which means that Django is already installed.
New Project
If you are using Django for the first time, you must make sure that some initialization is complete. That is, you need to automatically generate some code to create a Django project-a series of Django Setup instances, including database configuration, Django-specific options, and program-specific settings.
Using the command line, the CD enters the folder where you want to save your code, and runs the command django-admin.py startproject MySite. It creates a MySite folder in the current folder.
If you are installing Django via Python setup.py, django-admin.py will be in your system path.
If it's not in your path, you can find it in Site-packages/django/bin, Site-packages is your Python installation directory.
(I don't quite understand the above, I copy the django-admin.py to the folder where the code is stored, and then run the command django-admin.py startproject MySite to create the project).
Let's take a look at what Startproject has generated:
mysite/
__init__.py
manage.py
settings.py
urls.py
These files are:
1.__init__.py: An empty file that tells Python to think of this folder as a Python package. (If you're a beginner, read the official Python documentation to learn more about the package.) )
2.manage.py: A practical command line that lets us interact with Django projects in a variety of ways.
3.settings.py: Set/Configure Django Project
The URL mapping for the 4.urls.py:django project.