content
- Creation of the first Django project
- Introduction to the new project file of myproject
- Environment configuration for myproject project (meta-project)
- Running the myproject project
Creation of the first Django project
1. Create a virtual environment (virtualenv) for running the Django project, which is
not described in detail here, see - Django Learning Day 1 Content
2. Create the first Django project
cd Enter the Scripts under the virtual environment
testenv as shown below After
C:\env-all\envtest\Scripts>activate
and then cd to the folder directory where the myproject project is to be created,
create a project file named myproject django-admin startproject myproject generates a myproject project file
Introduction to the new project file of myproject
The created pyproject project includes 2 parts, a myproject project, and a manage.py file
1. manage.py file
A command line tool that allows us to interact with Django projects in various ways
2. myproject project
a — init . py :
b — settings.py
c — urls.py
d — wsgi.py
Environment configuration for myproject project (meta-project)
1.settings.py configure
a INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'stu', #Add the project file name you created here
]
b TEMPLATES = ['DIRS': [os.path.join(BASE_DIR, 'templates')],]
c DATABASES = [
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Database name—momo_mysql',
'USER': 'root',
'PASSWORD':'123456',
'HOST': 'localhost',
'PORT':'3306'
]
LANGUAGE_CODE = 'zh=hans'
TIME_ZONE = 'Asia/Shanghai'
d STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
e MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
There are still some things that need to be modified, and will continue to be supplemented and improved in the future
2.init.py配置
import pymysql
pymysql.install_as_MySQLdb()
Running the myproject project
python manage.py runserver
Note: You can add ip: port number after runserver
- python manage.py runserver ip: 8080
and then enter 127.0.0.1: 8000 in the browser window - the default port here is 8000
The result is shown as follows, which is the first A Django project file is successfully implemented