Please make sure that pyenv and python have been configured for the following codes, and the following codes are all run in the terminal.
mkdir demo //Create a demo folder cd demo //Enter the folder python3 -m venv myvenv// Create a virtual environment source myvenv/bin/activate //Enter the virtual environment pip install django==1.8 //Configure django under the virtual environment django-admin startproject mysite .//Create a project folder, mysite
Open the setting.py file in mysite and change TIME_ZONE to Asia/Shanghai. Then add at the bottom of this file
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
After running the database,
python manage.py migrate // configure the database (these codes run in the terminal) python manage.py runserver//run database
Here, the URL 127.0.0.0.1:8000 can be opened initially, but there is no content.
At this time, we need to write a web page, where to write it? Please see below:
First you need to change the url
from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^admin/', include(admin.site.urls)),//Add this link, url(r'', include('demo.urls')),]
Then create the demo folder, and create the urls.py file and add in this file:
from django.conf.urls import url from .import views//import
Then create the two folders templates/demo in the demo file, and create the list.html file in the demo file. At
this time, you will find a blank page when you open the web page again. Use your knowledge of html and css if you need to display something. This article does not introduce too much.