开发者

Production django server throwing "NoReverseMatch" while rendering, works on development

开发者 https://www.devze.com 2023-01-28 04:00 出处:网络
Caught NoReverseMatch while rendering: Reverse for \'views.main\' with arguments \'()\' and keyword arguments \'{}\' not found.
Caught NoReverseMatch while rendering: Reverse for 'views.main' with arguments '()' and keyword arguments '{}' not found.

I do开发者_开发技巧n't understand what would cause the error.

My urls

urlpatterns = patterns('',
url(r'^$', views.main),

html template

<a href="{% url views.main %}"> bla bla blah</a>

And in my views.py

return render_to_response("main.html", d, context_instance=RequestContext(request)) 

I've checked my TEMPLATE_DIRS and they seem to be pointing to the correct directory.


The likelihood is that you have an error somewhere else, which is preventing one of your views from being imported - probably a dependency missing on your production server. The reverse-URL functionality works by importing all your views, so if any of them can't be imported for any reason you'll see a NoReverseMatch error.


Try:

url(r'^$', views.main, name="main-view")

and on template:

<a href="{% url main-view %}"> bla bla blah</a>


I ran into the same thing, and so I tried Paperino's method of creating an image of the server and then restoring the server to that image, and voila, the template error went away. I have no idea why that works, but it did for me, so I'm not complaining, spent most of the day trying to figure this one out :)


Restarting gunicorn service solved my problem:

sudo systemctl restart YOUR_GUNICORN.service

Make sure that you are restarting the right gunicorn service. I was driving myself insane, and then I realized I was restarting the wrong service. You might also try restartingrestart nginx, but it shouldn't be necesary: sudo systemctl restart nginx

0

精彩评论

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