Jon
Jon

Reputation: 3194

Django - NoReverseMatch at

I am trying to sync two Django projects and am finding myself with the following error:

Reverse for 'file-add' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

There seems to be a problem now with the template, line 15:

5   
6   
7   {% block content %}
8   
9   {% if form.non_field_errors %}
10  <div class="panel">
11    {{ form.non_field_errors }}
12  </div>
13  {% endif %}
14  
15  <form action="{% url 'file-add' %}" method="post" enctype="multipart/form-data">
16    <fieldset>
17      <legend>Add CV</legend>
18  
19      <div class="large-12 columns">
20        <div class="row" id="file_container">
21          {% if form.f.errors %}
22          <input placeholder="First name" name="f" type="file" id="file" class="error" />
23          {% else %}
24          <label for="f" name="CV" />
25          <input name="f" type="file" id="file" />

Since I don't remember changing this template in any way, and all the files should be the same as the ones on my other server, are there any small issues then I am missing?

> <form action="{% url 'file-add' %}" method="post" enctype="multipart/form-data">

EDIT

It seems to be something to do with my urls files. I have a main urls file, which forwards anything with the url "/jobs/" to the jobs url file.

url(r'^jobs/', include('jobs.urls', namespace="jobs")),
url(r'^admin/', include(admin.site.urls)),
url(r'^admin_tools/', include('admin_tools.urls')),

The jobs urls file then points to the relevant jobs pages.

url(r'^new', views.importDemoData, name='importDemoData'),
url(r'^add', FileAddView.as_view(), name='file-add'),
url(r'^files/list', FileListView.as_view(), name='list'),

# This view lists uploaded files
url(r'^success', FileListView.as_view(), name='home'),
url(r'^(?P<unique_id>\w+)/$', views.application, name='application'),

If I move the "file-add" line into the main urls file, it seems to work...

Upvotes: 2

Views: 358

Answers (4)

Varun Chadha
Varun Chadha

Reputation: 376

I think you should add namespace front of URL name

Upvotes: 1

nitansh bareja
nitansh bareja

Reputation: 302

You forgot to add namespace before the URL name

The Reverse of "jobs/add" will {% url 'jobs:file-add' %} which is {% url 'namespace:name'%}.

When you removed the namespace it worked because the 'jobs/add' url will match with {% url 'file-add' %}

Upvotes: 0

AlvaroAV
AlvaroAV

Reputation: 10553

As they say in their documentation: url-namespaces-and-included-urlconfs

URL namespaces of included URLconfs can be specified in two ways.

Firstly, you can provide the application and instance namespaces as arguments to include() when you construct your URL patterns. For example,:

url(r'^polls/', include('polls.urls', namespace='author-polls', app_name='polls')),

This will include the URLs defined in polls.urls into the application namespace 'polls', with the instance namespace 'author-polls'.

Secondly, you can include an object that contains embedded namespace data. If you include() a list of url() instances, the URLs contained in that object will be added to the global namespace. However, you can also include() a 3-tuple containing:

(<list of url() instances>, <application namespace>, <instance namespace>)

Upvotes: 0

Jon
Jon

Reputation: 3194

If someone could explain this to me that would be great..

I removed the namespace from this line in the main urls file:

url(r'^jobs/', include('jobs.urls', namespace="jobs")),

changing it to:

url(r'^jobs/', include('jobs.urls')),

and it worked! This is a little weird as it seems to be working fine like that on my other server..

Upvotes: 0

Related Questions