创建项目 [root@localhost ~]# django-admin.py startproject project0904 [root@localhost ~]# ls project0904 [root@localhost ~]# cd project0904/ [root@localhost project0904]# ls manage.py project0904 创建应用 [root@localhost project0904]# python manage.py startapp app0904 [root@localhost project0904]# ls app0904 manage.py project0904 设置数据库,默认SQLite [root@localhost project0904]# python manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying sessions.0001_initial... OK 创建超级管理员及密码 [root@localhost project0904]# python manage.py createsuperuser Username (leave blank to use 'root'): admin Email address: test@test.com Password: Password (again): Superuser created successfully. 设计应用静态页 [root@localhost project0904]# cd app0904/ [root@localhost app0904]# vi views.py from django.shortcuts import render # Create your views here. from django.http import HttpResponse def main(request): html = '<html>\n' \ '<body>\n' \ '<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">\n' \ 'Django Test Page\n' \ '</div>\n' \ '</body>\n' \ '</html>\n' return HttpResponse(html) "views.py" 13L, 403C written [root@localhost app0904]# cd .. 备份vurls文件 [root@localhost project0904]# mv project0904/urls.py project0904/urls.py.bak 配置urls文件 [root@localhost project0904]# vi project0904/urls.py from django.conf.urls import url from django.contrib import admin from app0904 import views urlpatterns=[ url(r'^$',views.main), url(r'^admin/',admin.site.urls)] "project0904/urls.py" [New] 7L, 163C written [root@localhost project0904]# vi project0904/settings.py 只添加应用 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app0904', ] 启动应用,0.0.0.0可通过ip访问 [root@localhost project0904]# python manage.py runserver 0.0.0.0:8000 Performing system checks... System check identified no issues (0 silenced). September 03, 2016 - 23:56:39 Django version 1.10.1, using settings 'project0904.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C.
目录介绍
project0904 ├── manage.py └── project0904 ├── __init__.py ├── settings.py ├── urls.py └── wsgi.py | app0904/ ├── __init__.py ├── admin.py ├── models.py ├── tests.py └── views.py