Create a project and create a project
If this is your first time using Django, you will have to pay attention to some initialization steps. You will need to automatically generate some code to create a Django project-it is a collection of settings for Django instances, including database settings, specific Django options and specific application options.
From the command line, cd to the directory where you want to store your code, and then use the following command:
This will create a mysite directory under your current directory. If it doesn't work, see here https://docs.djangoproject.com/en/1.7/faq/troubleshooting/#troubleshooting-django-admin-py
Note: You will need to avoid naming projects as built-in python or Django content. In particular, this means that you should avoid using names such as django (which will conflict with Django itself) or test (which will conflict with a built-in python package. |
Where should the code be stored? If you have used the old PHP (or have not used the modern framework ), you may be used to placing code in the root directory of the web server root document (such as/var/www ). In Django, you do not need to do that. Putting any python code under the document root directory of the web server is not a good idea, because it increases the possibility of risks so that people may view your code through the web. It is not safe. Put your code in a directory outside the root directory of the document, such as/home/mycode. |
Let's take a look at the created startproject:
Does it not match what you see? The default project layout has recently changed. If you see a "flat" layout (no internal mysite directory), you may use Django that does not match this guide. You will either downgrade the guide or update Django. |
These files are:
1. The external mysite/root directory is a package for your project. Its name has no effect on Django; you can rename it to anything you like.
2 manage. py: a command line program that allows you to interact with Django in various ways. You can read all the details about manage. py here https://docs.djangoproject.com/en/1.7/ref/django-admin/
3. The internal mysite/directory is the actual python package of your project. Its name is the python package name (for example, mysite. urls) that you will use to import anything ).
4 mysite/_ init _. py: An empty directory that tells python that the directory should be considered a python package. (If you are a python beginner, read the official pythondocument in http://docs.python.org/tutorial/modules.html?packages)
5 mysite/settings. py: set or configure the django project. Bytes.
6 mysite/urls. py: URL Declaration for this django project; a "content list" for your django-driven site ". You can read