urls。py:
url(r ^book/(?P<booktitle>[w。_-]+)/(?P<bookeditor>[w。_-]+)/(?P<bookpages>[w。_-]+)/(?P<bookid>[d。_-]+)/$ , book。views。book , name="book"),
意见:
def book(request, booktitle, bookeditor, bookpages, bookid, template_name="book。html"):
book = get_object_or_404(book, pk=bookid)
if booktitle != book。book_title :
redirect_to = "/book/%s/%s/%s/%s/%i/" % ( booktitle, bookeditor, bookpages, bookid, )
return HttpResponseRedirect(redirect_to)
return render_to_response(template_name, { book : book, },)
。
因此,每本书的长篇都一样:
example。com/book/the-bible/gesu-crist/938/12/
I want that if there is an error in the url, then I get redirected to the real url by using book。id in the end of the url。
例如,我要谈谈:
example。com/book/A-bible/gesu-crist/938/12/
之后,我将转而处理:
example。com/book/the-bible/gesu-crist/938/12/
。
但是,如果我去做错的话,我会发现这一错误:
TypeError at /book/A-bible/gesu-crist/938/12/
%d format: a number is required, not unicode
。
如果我使用百分比,我就会发现这一错误:
*The page isn t redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete。 * This problem can sometimes be caused by disabling or refusing to accept cookies。*
Why ? What I have to do ?