django的返回方式

django的返回方式
参考:http://docs.djangoproject.com/en/1.2/topics/http/shortcuts/
1 直接渲染
return render_to_response('mark/projects.html', {'latest_project_list': latest_project_list})
这样参数都直接写进去了
2 重定向
1.

By passing some object; that object's get_absolute_url() method will be called to figure out the redirect URL:

def my_view(request):
...
object = MyModel.objects.get(...)
return redirect(object)

2.

By passing the name of a view and optionally some positional or keyword arguments; the URL will be reverse resolved using the reverse() method:

def my_view(request):
...
return redirect('some-view-name', foo='bar')

3.

By passing a hardcoded URL to redirect to:

def my_view(request):
...
return redirect('/some/url/')

This also works with full URLs:

def my_view(request):
...
return redirect('http://example.com/')

By default, redirect() returns a temporary redirect. All of the above forms accept a permanent argument; if set to True a permanent redirect will be returned:

def my_view(request):
...
object = MyModel.objects.get(...)
return redirect(object, permanent=True)

3
def current_datetime(request):
now = datetime.datetime.now()
html = "It is now %s." % now
return HttpResponse(html)
or
return HttpResponseNotFound('

Page not found

')
or
return HttpResponse(status=201)