As the title implies I've got the NoReverseMatch error, but my url.py has the corresponding named url. I feel pretty confident I've missed something simple, but being new I can't seem to find my own problem.
ERROR: (Generated in the below employee_edit.html file)
Caught NoReverseMatch while rendering: Reverse for ''employee_new''
with arguments '()' and keyword arguments '{}' not found.
\home\username\mysite\myapp\views.py:
class v_EmployeeCreate(CreateView):
model = Employee
template_name = 'employee/employee_edit.html'
def get_success_url(self):
return reverse('employee_list')
\home\username\mysite\url.py:
from myapp.views import v_EmployeeCreate, v_EmployeeList
urlpatterns = patterns('',
< ... snip ...>
url(r'^newEmployee$', v_EmployeeCreate.as_view(), name="employee_new"),
)
\home\username\mysite\myapp\templates\employee\employee_edit.html (line 7):
<form action="{% url 'employee_new' %}" method="POST">
I feel like there is a file path issue, but I'm not sure how I would resolve that. The named URL works to get me to the template, but then the template itself fails to generate a url.
For the sake of documentation so far I have:
reloaded django
checked spelling
confirmed non-template functionality (Same setup without the template tags is fine. page loads)
Working from tutorial: http://effectivedjango.com/tutorial/views.html#creating-contacts
I think you are using an old version of Django - before 1.5 (current is 1.6). The clue is that your error message has two single-quotes around the view name: in those older versions, you shouldn't put quotes around the name in the url tag.
You should (preferably) upgrade Django, or (if you really can't do that) use {% url employee_new %}
Related
Error while passing value to view from template using url
Error :
Error during template rendering
In template D:\TONO\DJANGO_TASK\user_auth\templates\auth_app\other-user-listing.html, error at line 114
Reverse for 'add_to_group' with arguments '(name: Administrator,)' not found. 1 pattern(s) tried: ['auth_app\\/<str:username>/']
This my urls.py
url(r'^<str:username>/', views.add_to_group, name="add_to_group"),
This is the call from template
<i class="icon-plus">Add</i>
In your call from template see if you do this if that solves the problem, I remember I was facing this issue and this is what I did:
The syntax for specifying url is {% url namespace:url_name %}. So, check if you have added the app_name in urls.py.
Your url defines a named argument for the url "add_to_group". You should pass this argument as a keyword argument
{% url 'add_to_group' username=username %}
You are mixing the new and old style urls. To use the new style you should use path
path('<str:username>/', views.add_to_group, name="add_to_group"),
Error corrected using :
url(r'^auth_app/add_to_group/(?P<username>[-\w]+)/$', views.add_to_group, name='add_to_group'),
Everything was working fine when i have added fobi in my project but somehow while i have added namespace in my url it start giving me the error like below.
Main urls.py
re_path(r'^formbuilders/', include('apps.form_builders.urls'),),
Form_builders urls.py
url(_(r'^$'), view=dashboard, name='fobi.dashboard'),
Template
{% url 'fobi.dashboard' as fobi_dashboard_url %}
Reverse for 'fobi.dashboard' not found. 'fobi.dashboard' is not a valid view function or pattern name.
I have visited many site but did not received any quick fix.
Could you please help me out to fix this issue?
continuing question from here. after fixing the template according to #dannyroa - removing the quotes from the template name I still get NoReverseMatch error:
NoReverseMatch at /transfers/41/
Reverse for 'description_url' with arguments '(u'\u05ea\u05e7\u05e6\u05d9\u05d1 \u05d4\u05e9\u05db\u05e8 - \u05d1\u05d9\u05ea \u05d4\u05e0\u05e9\u05d9\u05d0',)' and keyword arguments '{}' not found.
Request Method: GET
Request URL: http://127.0.0.1:8000/transfers/41/
Django Version: 1.4
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'description_url' with arguments '(u'\u05ea\u05e7\u05e6\u05d9\u05d1 \u05d4\u05e9\u05db\u05e8 - \u05d1\u05d9\u05ea \u05d4\u05e0\u05e9\u05d9\u05d0',)' and keyword arguments '{}' not found.
the template now:
<a href='{% url description_url transfer.description %}'>{{transfer.description}}</a>
the urlconf:
url(r'^description/(?P<description>[\w ]+)/$',
'transfers.views.description_ListView',
name = 'description_url')
the view:
def description_ListView(requesst,**kwargs):
template_name = 'transfers/description.html'
o = get_list_or_404(Transfer, description =kwargs['description'])
#print ('o:',o)
context_object_name = "transfer_name_list"
return render_to_response(template_name,{context_object_name:o,'description':kwargs['description']})
this problem is really starting to get me down. I know I can write a specific method on the Transfer Model (maybe with #permalink) returning the right url for each view. but this is a lot of work and certainly frustrating to do this only because of my miserable failure at using the {%url %} template tag
thanks for the help
This is my previous post. Template includes and django views/urls. How (do/should) they work? .
Again, the mini box works fine. I've taken the advice given and trying to work with it.
So I have a profile(request, profile_type, username) view. I'm trying to grab the 'profile_intros'context from that and place it into the included mini_profile.html template.
I've tried making an inclusion tag(as I will be needing it elsewhere throughout the site):
#register.inclusion_tag('includes/profile_info.html', takes_context=True)(profile_info)
def profile_info(context):
profile_intros = FundRecommendation.objects.filter(investor=profile).count()
return{
'profile_intros' : context['profile_intros'],
}
and throwing {% profile_info %} into the included mini_profile.html template. I've followed the django doc example and I really don't know what I'm doing wrong.
I'm getting :
Exception Type: TemplateSyntaxError
Exception Value: Invalid block tag: 'profile_info'
You forgot to use {% load ... %} to load the template tag library.
in views.py I have this:
def logout(request,key):
auth.logout(request)
return HttpResponseRedirect(reverse('airAgency.views.index',args=[key]))
in index template i wanna when user click on a link,logout view run:
logout
I wanna pass key parameter to logout view,Imagine I have an object named agn and it's WebSite field is going to pass to logout view, s.th like this:
<a href="{% url airAgency.views.logout agn.WebSite %}">
Imagine agn.WebSite has the value of mastane above code cause this error:
Caught NoReverseMatch while rendering: Reverse for 'airAgency.views.logout' with arguments '(u'mastane',)' and keyword arguments '{}' not found.
what's the right way to do this?
Caught NoReverseMatch - usually means that the url is being called by incorrect arguments, or that something else is wrong when {% url %} tries to call the url specified.
You need to define url pattern for that view function to be called in urls.py. And in the url pattern specify a view function.
urls.py
url(r'^logout/(?P<key>[a-zA-Z0-9\-]+)/$', "airAgency.views.logout", name="logout"),
index.html
<a href="{% url logout agn.WebSite %}">
This might not work if you just copy paste it because I don't know the exact project setup.
The key is to have urls.py where regex is used to create patterns for how the url looks like, then a view function that needs to be invoked, and finally a name, which you can then use in your templates.
This is all explained in the basic Django tutorial.