码迷,mamicode.com
首页 > 编程语言 > 详细

python 点滴记录13:django 初尝试

时间:2015-07-02 17:44:53      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:django   python   

use django to create website:


1、create new django project

#django-admin.py startproject test1
test1/
├── manage.py
└── test1
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py


2、create new django application,in the new project directory:

#python manage.py startapp web
test1/
├── manage.py
├── test1
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   └── wsgi.py
└── web
    ├── admin.py
    ├── __init__.py
    ├── migrations
    │   └── __init__.py
    ├── models.py
    ├── tests.py
    └── views.py


3、add the new application to project‘s settings.py in INSTALLED_APPS:

INSTALLED_APPS = (
    ‘django.contrib.admin‘,
    ‘django.contrib.auth‘,
    ‘django.contrib.contenttypes‘,
    ‘django.contrib.sessions‘,
    ‘django.contrib.messages‘,
    ‘django.contrib.staticfiles‘,
    ‘test1‘,
)

4、create view in the application‘s views.py:

from django.http import HttpResponse
def index(request):
        return HttpResponse("hello django!")


5、in project‘s urls.py,add mapping to the application:

from test1.views import index
urlpatterns = patterns(‘‘,
    url(r‘^test1/‘, ‘test1.views.index‘),
)


6、url:http://ip:8000/test1 


python 点滴记录13:django 初尝试

标签:django   python   

原文地址:http://ahaii.blog.51cto.com/1695127/1670209

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!