java python web框架_初学python的Web框架Django-模板

修改django的url规则和模板的基本操作

We’ll just have to take a few steps to make the conversion. We will:

1. Convert the URLconf.

2. Rename a few templates.

3. Delete some of the old, unneeded views.

4. Fix up URL handling for the new views.

bear@njava:~/njava$ vi urls.py

urlpatterns = patterns('',

# Example:

# (r'^tt/', include('tt.foo.urls')),

# Uncomment the admin/doc line below and add 'django.contrib.admindocs'

# to INSTALLED_APPS to enable admin documentation:

# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:

(r'^$','tt.news.views.index'),

(r'^news-(?P\d+).html/$','tt.news.views.detail'),

(r'^news/$','tt.news.views.index'),

(r'^admin/', include(admin.site.urls))

)

bear@njava:~/njava$ cd news

bear@njava:~/njava/news$ vi views.py

# Create your views here.

from django.shortcuts import render_to_response,get_object_or_404

#from django.http import HttpResponse

from tt.news.models import Post

def index(request):

posts = Post.objects.all().order_by('-pub_date')[:5]

#return HttpResponse("Hello,m44,this index.")

return render_to_response('news/index.html',{'posts':posts})

def detail(request,post_id):

p=get_object_or_404(Post, pk=post_id)

return render_to_response('news/detail.html',{'post':p})

link:http://docs.djangoproject.com/en/1.2/intro/tutorial03/#intro-tutorial03

http://docs.djangoproject.com/en/1.2/intro/tutorial04/#intro-tutorial04

星期四, 五月 20th, 2010

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值