Django in Python creates the first project (hello, world)

For convenience, we use the free version of the pycharm community. The free version does not have the direct function of supporting Django and web development. This function is only available in the professional version. But as a novice, we still use the community version to send, which helps us to understand the details of the program principle and help us improve. In actual development, we need to open both pycharm and command line tools at the same time.

General steps for Django to create a project:

1. New project (command line) >django-admin startproject mysite //mysite is the project name

Then open pycharm and view the current file:first step

2. Modify the project > python manage.py startapp helloapp //helloapp is the application name (key, see below for details)

Directory created by this step:second step

After the modification project command is executed, we need to do the following:

  1. Modify the views.py file //views.py to include a response to a certain http request (ie url).
  2. Modify the path relationship between the specified url and the processing function in URL routing //urls.py.

3. Run the project>python manage.py runserver //Open a server with runserver

Then we can enter the address and port number to access.

Note two points:

When creating a project, you need to cd to the location where you want to create the project, and then modify the project to cd to the created project. In addition, one uses Django-admin to create and modify the project, and the other uses manage.py (do not use this before). dropped python), do not confuse the two.

django-admin与manage.py

The former is the global management tool of the django framework, and its functions mainly include:

  1. Create and manage Django projects.
  2. Build and manage databases used by Django tools
  3. Control debug or log information
  4. Run and maintain Django projects

You can view its functions through />django-admin help

###manage.py is similar to django-admin, but only for the current project. We can use it to create an application in the current application, and it can also be used to create a server for the current project.

/>python manage.py help can view its main functions

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325446399&siteId=291194637