我遇到了以下代码行的问题,并在其中传递了一个带有空格的争论。
<a href="{% url graph_exercisename exercise_name=e.exercisename|slugify %}" class="button" >Graph</a>
当我从html文件中删除上面的代码时,页面编译得很好。当一个没有空格的arg传递给exercise_name时,它也会编译。
这是我的网址格式
urlpatterns = patterns('',
url('^exercises/(\d{1,6})/$', exercises,name='displayexercises'),
url('^workouts/$',workouts,name="displayworkouts"),
url('^graph/$',bodyweight_graph),
url('^graph/(?P<exercise_name>\w+)/$',graph_exercisename,name="graph_exercisename"),
)
最后是观点:
def graph_exercisename(request,exercise_name):
exercise_name = exercise_name.replace('-'," ").title()
exercises = Exercise.objects.filter(workout__user=request.user.id).filter(exercisename = exercise_name)
exercises = exercises.order_by('workout__workoutdate')[:10]
values = Rep_Table(exercises).table
return render(request,'graph.html',{'values':values})
更奇怪的是,Django根本没有在错误页面上给我任何代码,它只是声明Django遇到了错误。
感谢您的帮助!
答案 0 :(得分:2)
请更改您的网址:
url('^graph/(?P<exercise_name>\w+)/$',graph_exercisename,name="graph_exercisename"),
为:
url('^graph/(?P<exercise_name>[^/]+)/$',graph_exercisename,name="graph_exercisename"),