NoReverseMatch, Not working in Production Server

62 views
Skip to first unread message

miguel vfx

unread,
May 8, 2017, 9:53:54 AM5/8/17
to Django users
Hi,

It used to work but after my recent upload, it stopped. Does anyone encountered this kind of error before?

It's working fine in my local machine using runserver but not in the production server. I'm basically drag and dropping files. Then renaming the
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sym.settings') in views. I only have that in views.py.

After that, I restart the app in supervisorctl.

The production server is using gunicorn, nginx. The Django version is 1.10.5 with python 3.5. My local machine is using the same django version (I just updated it) but with python 3.4.

Error page:

Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'rrs_class_lists_faculty' with arguments '()' and keyword arguments '{'faculty_id': ''}' not found. 1 pattern(s) tried: ['rrs/class_lists_faculty/(?P<faculty_id>[-\\w]+)/$']

<td class="col-xs-12">{{ forloop.counter }}. <a href="{% url 'rrs_class_lists_faculty' faculty_id=faculty_name.1 %}" target="_blank">{{ faculty_name.0 }}</a></td> 

  1.  return render(request, 'rrs_class_list_summary.html', {'errorLS': errorLS,
  2.                                                            'feedbackLS': feedbackLS,
  1.                                                            'faculty_link_name_list': faculty_link_name_list,
    ...
  1.                                                            })
urls.py
 
     url(r'^class_lists_faculty/(?P<faculty_id>[-\w]+)/$', rrs_views.requires_login(rrs_views.class_lists_faculty), name="rrs_class_lists_faculty"),

views.py
def class_lists_faculty(request, faculty_id=''):

I have been stuck on this for half a day now. My biggest trouble is its working fine in runserver which really leaves me clueless on what's happening on the web server. I would really appreciate any help. Thank you in advance.

miguel vfx

unread,
May 8, 2017, 10:16:31 AM5/8/17
to Django users
I got it to work but with a different approach by not passing arguments:
<a href="{% url 'rrs_class_lists_summary' %}{{ faculty_name.1 }}/" target="_blank">{{ faculty_name.0 }}

    url(r'^class_lists_summary/$', rrs_views.requires_login(rrs_views.class_lists_summary), name="rrs_class_lists_summary"),

    url(r'^class_lists_summary/(?P<faculty_id>[-\w]+)/$', rrs_views.requires_login(rrs_views.class_lists_faculty), name="rrs_class_lists_summary"),

Does this make any sense? I would like to use the first one since it's much cleaner.

ludovic coues

unread,
May 8, 2017, 10:47:25 AM5/8/17
to django...@googlegroups.com
I'm a bit surprised by the error message showing
(?P<faculty_id>[-\w]+) with two \ while your url only use one.

If you want to try quickly different arguments for your reverse tag,
you can use the django shell.

python manage.py shell
>>> from django.urls import reverse
>>> reverse('rrs_class_lists_faculty', kwargs={"faculty_id": 1})

Good luck
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/619b3527-0e30-4fae-ba6c-0d273d336c6d%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Ludovic Coues
+33 6 14 87 43 42

Melvyn Sopacua

unread,
May 8, 2017, 12:17:32 PM5/8/17
to django...@googlegroups.com

On Monday 08 May 2017 12:46:43 ludovic coues wrote:

 

> I'm a bit surprised by the error message showing

> (?P<faculty_id>[-\w]+) with two \ while your url only use one.

 

No, that's normal since a few releases, that backslashes in backtraces are escaped. Don't ask me why, I've learned to read it and didn't dive down the rabbit hole.

 

--

Melvyn Sopacua

Melvyn Sopacua

unread,
May 8, 2017, 12:23:22 PM5/8/17
to django...@googlegroups.com

On Monday 08 May 2017 03:16:30 miguel vfx wrote:

> I got it to work but with a different approach by not passing

> arguments:

 

This isn't the right fix, something else changed. The error message shows that faculty_name.1 was empty. If the fix works, the old code should work as well. It's probably the data that changed - but you're not showing the for loop and view part that fills faculty_name.

 

> >> Reverse for 'rrs_class_lists_faculty' with arguments '()' and

> >> keyword

> >> arguments '{'faculty_id': ''}' not found.

--

Melvyn Sopacua

Melvyn Sopacua

unread,
May 8, 2017, 3:16:14 PM5/8/17
to django...@googlegroups.com

Just a shot in the dark - if you're rendering choices for a choice field, then this would be empty for the "I didn't pick anything" option indicated by '---------'. To fix it use forloop.first to not render the url tag, check for emptiness or use the |default: template filter.

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages