在我的应用程序Django的网址错误 [英] django url error in my app
问题描述
我有一个Django应用程序在那里我有以下网址:
I have a django app where i have the following urls:
urlpatterns = patterns('',
url(r'^$', views.acadprogram, name='acadprogram'),
url(r'^(?P<program_code>\d+)/$', views.acadprogram2, name='programcode'),
)
和这是我有我的看法:
def acadprogram2(request, program_code):
name = Program_requirement_category.objects.get(name=program_code)
descendants = name.get_descendants(include_self=True)
return render_to_response("courses.html", {'nodes':descendants.all()}, context_instance = RequestContext(request))
在我的HTML,我打电话这个网址是这样的:
and in my html, i am calling this url like this:
<a ng-repeat="prog in programs | orderBy:'academic_program.program_title' | orderBy:'primary_program':true" href="/acadprog/{{prog.academic_program.acad_program_code}}/" ng-click="display.addprogram = false" class="list-group-item">
{{prog.academic_program.program_title}}
但是,当我的href点击,Django的抛出我找不到错误的URL。我去哪儿了?
But when i click on the href, django throws me a url not found error. Where did i go wrong?
推荐答案
按照评论...
您角的应用正在生成一个URL,如:127.0.0.1:8000/acadprog/AS.SCIENCE
Your Angular app is generating a url like: "127.0.0.1:8000/acadprog/AS.SCIENCE"
这就是问题所在 - URL模式期待一个数(P&LT; program_ code&GT; \\ D +?)
所以这个网址不是由Django的匹配。
That is the problem - the url pattern is expecting a number (?P<program_code>\d+)
so this url is not matched by Django.
您可以更改URL模式:
You could change the url pattern to:
url(r'^(?P<program_code>.+)/$', views.acadprogram2, name='programcode'),
...这将会匹配1或更多的字符任意的。
...this would would match 1-or-more of any chars.
这篇关于在我的应用程序Django的网址错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!