django admin 设置

作者: admin 分类: python 发布时间: 2011-07-20 14:18 ė 6 没有评论

# Include these import statements…
from django.contrib import admin
from django.conf.urls.defaults import *
admin.autodiscover()

# And include this URLpattern…
urlpatterns = patterns(”,
    # …
    (r’^admin/’, include(admin.site.urls)),
    # …
)

顺便理清下自己最近学习PYTHON的思路

 先是URLS  在是VIEWS 然后是模版template

如果新做项目

python manage.py startapp books
接下来编辑books/model.py 里面的文件
添加需要做的数据库
python manage.py validate  这个命令验证模型的有效性
 
python manage.py sqlall books   这个命令查看转换出来的SQL语句
 
python manage.py syncdb      这个命令将SQL 添加到库里
 

模版系统

修改setting.py 将里面TEMPLATE_DIRS = (
           '/var/mysite/html',
)
修改views.py
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import Template, Context
def ua_display_bad(request):
        ua=request.META['HTTP_USER_AGENT']
        return HttpResponse("Your browser is %s" % ua)

def ua_display_good1(request):
        try:
            ua=request.META['HTTP_USER_AGENT']
        except KeyError:
            ua='unknown'
        return HttpResponse("Your browser is %s" % ua)

def ua_display_good2(request):
        ua=request.META.get('HTTP_USER_AGENT','unknown')
        return HttpResponse("Ypur brow is %s" % ua)

def search_form(request):
    return render_to_response('search_form.html')

 

 

URLS里面的设置

 

# Include these import statements...
from django.contrib import admin
from django.conf.urls.defaults import *
from views import *
admin.autodiscover()

# And include this URLpattern...
urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^good1/',ua_display_good1),
    (r'^good2/',ua_display_good2),
    (r'^display/',ua_display_bad),
    (r'^search-form/$',search_form),
)

 

没办法啊 我新手刚学PYTHON。所以记录下来 免的老忘掉 理清思路

本文出自 小Q,转载时请注明出处及相应链接。

本文永久链接: http://www.linuxqq.com/archives/736.html

0
更多
Ɣ回顶部