Create a basic process for Django. Create a process for Django

Source: Internet
Author: User

Create a basic process for Django. Create a process for Django
Django creation process

1. Create a project: django-admin startproject project name

2. Create an application: python manage. py startapp Application name

3. Activate the project: Modify INSTALLED_APPS in the settings. py file. Add the 'Application name' at the end of the list'

4. Configure the mysql database:

Install the pymysql library before configuration.
1) modify the global _ init _. py file in the project directory. Write the following code:
import pymysqlpymysql.install_as_MySQLdb()

 

2) Modify DATABASES in the settings. py file. Change it to the following:

DATABASES = {'default': {'Engine ': 'django. db. backends. mysql ', 'name': 'database name', 'user': 'database Username', 'Password': 'database password', 'host': 'localhost ', 'post': '200 '}}

 

5. Create a model class: create a data table in the models. py file under the application directory.

6. Generate a migration file: python manage. py makemigrations

7. Execute the migration file: python manage. py migrate

8. Configure the site

9. Create a template directory and an application template directory

10. Modify the global urls. py file in the project directory. The modified content is as follows:

Urlpatterns = [path ('admin/', admin. site. urls), path ('application name/', include ('application name. urls')]

 

11. Create and configure urls. py in the application directory. The content is as follows:

From django. urls import pathfrom. import viewsurlpatterns = [path ('route path', views. Corresponding function),]

 

12. Configure the Application Template path in the settings. py file.

Change the DIRS content in the TEMPLATES list:'Dirs': [OS. path. join (BASE_DIR,'Templates')]

13. Place the front-end files in the template folder.

14. Write view functions in the views. py file

Django creation process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.