开发者

django url tag problem

开发者 https://www.devze.com 2023-02-11 23:18 出处:网络
开发者_如何学编程I have problem with url tag. I want to redirect to a function that is in for eg
开发者_如何学编程

I have problem with url tag. I want to redirect to a function that is in for eg project_name.forum.views.function. Here is how i try to create url

{% url forum.views.function %}

it gives me this error:

Caught ViewDoesNotExist while rendering: Tried forum in module project_name.forum.views. Error was: 'module' object has no attribute 'forum'

I added this url in urls.py(I can access it directly) What am I doing wrong?


The url tag is used to reference named urls. E.g.

url(r'^$', 
    login_required(views.user_babies),
    name='babystats_user_babies'),

Then you use {% url babystats_user_babies %} (the url pattern name, not the view name)


It sounds more like an incorrectly set up URL conf. You get that error when you specify a view that doesn't exist.

The url tag failing gives you a failure to reverse url with params... message.

What does your URL conf look like? Does project_name.forum.views.forum exist?

I mean, I find it odd you can visit the page at all, but that's the first place I'd look.


I have seen this error before with django url reversing stemming from the urlconf being set up with a root like projectname.app.views.view instead of app.views.view, so it chokes on the reverse without the name of the project.

Another common issue would be that the url takes an extra parameter that can be blank, and it needs you to pass an empty string or whatnot.

0

精彩评论

暂无评论...
验证码 换一张
取 消