Django doc summary (1)
2015-12-10 22:30
429 查看
Demo
Install Verifing
C:\Users\sam_rui>python --version Python 3.5.0 C:\Users\sam_rui>python Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> print(django.get_version()) 1.9 >>>
Create a demo project
cd into a directory, then create a demo project.D:\SamProject\django>django-admin startproject samsite
Start a dev server
D:\SamProject\django\samsite>python manage.py runserver Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. December 04, 2015 - 17:25:36 Django version 1.9, using settings 'samsite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.
Start a app
D:\SamProject\django\samsite>python manage.py startapp samapp
Now, the directory tree is like below.
D:\SamProject\django\samsite>tree /F Folder PATH listing Volume serial number is 0000003E F203:C3A2 D:. │ db.sqlite3 │ manage.py │ ├─samapp │ │ admin.py │ │ apps.py │ │ models.py │ │ tests.py │ │ views.py │ │ __init__.py │ │ │ └─migrations │ __init__.py │ └─samsite │ settings.py │ urls.py │ wsgi.py │ __init__.py │ └─__pycache__ settings.cpython-35.pyc urls.cpython-35.pyc wsgi.cpython-35.pyc __init__.cpython-35.pyc
Start a new view
add code in file 'samapp/views.py'from django.shortcuts import render from django.http import HttpResponse def index(request): return HttpResponse("Hello, this is sam site.")
add a internal url conf file in samapp directory
urls.py
from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name='index'), ]
modify the site url conf
samsite/urls.py
from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^samapp/', include('samapp.urls')), ]
restart the server and view the url 'http://127.0.0.1:8000/samapp/'
相关文章推荐
- MFC-SetWindowPos-位图按钮-扩展对话框-更改Logo
- 将语音搜索集成到Google Now中
- django上传文件原理解析
- OC block Category
- Django学习笔记<三>
- BestCoder Round #53 (div.2) C.Rikka with Graph II(dfs)
- 什么是测试开发工程师-google的解释
- windows下构建Go程序
- google map
- go的Type switch是一个switch语句么?
- 简单 Goroutine 池实现
- Django教程笔记:六、中间件middleware
- 毕业设计——001Google搜索
- [django-xadmin]如何在 search_fields和list_filter 中包含外键字段
- GoEasy在web端推送及接收
- Codeforces 437E The Child and Polygon(间隔DP)
- LeeCode Algorithm #3 Longest Substring Without Repeating Characters
- Google的Guava它Collection升华
- Getting Started with Django Logging in 5 Minutes
- Paragon NTFS for Mac