django create a project

1. Create a django project:

django-admin startproject projectname

 2. Create the database:

python manage.py syncdb

 3. Create APP:

python manage.py startapp appname

4. Create the data model corresponding to the App:

Define your own data model in models.py in the App directory

 5. Add the newly created App to the entire django project:

Add the name of the app you just created to the INSTALLED_APPS tuple of the setting.py file

 6. Update the database to generate an uncreated data model in the database:

python manage.py makemigrations
python manage.py migrate

 After completion, we can see our corresponding data table in the database.

 

7. Create a template:

1. Set the template directory: modify setting.py
2. Create a template directory
3. Create a view (views.py) corresponding to the App in the template directory
4. Add background processing code in views.py: business processing function
5. Configure the requested URL interception path: modify the urls.py file

8. Run the server and enter the URL test:

python manage.py runserver

 9. Set the built-in management interface for interface management:

1. Modify the urls.py in the directory and add the code: admin.autodiscover()
2. Register your own data model in urls.py in the App directory:
from modelis import modelName (own data model name)
admin.site.register(modelName)
Enter the management interface http://localhost:8000/admin to see your own data model and manage it (add and delete data)

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326913389&siteId=291194637