1.创建项目project
django-admin.py startproject myblog
查看目录树
alias tree="find . -print | sed -e ‘s;[^/]*/;|____;g;s;____|; |;g‘"
2.创建应用app
一个工程里可以创建很多个应用app, 一个app就是一个功能模块,我们创建一个blog应用:
cd myblog 打开目录
python manage.py startapp blog 创建名为blog的app
此时目录为:
|____blog | |______init__.py | |____admin.py | |____apps.py | |____migrations | | |______init__.py | |____models.py | |____tests.py | |____views.py |____manage.py |____myblog | |______init__.py | |______init__.pyc | |____settings.py | |____settings.pyc | |____urls.py | |____wsgi.py
将新建的blog加入到工程中,打开myblog/setting.py添加blog
INSTALLED_APPS = [ ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘, ‘blog‘, ]
启动工程:python manage.py runserver
3.
时间: 2024-10-15 15:41:22