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
Related
I have following code in urls.py
urlpatterns=[
path('estimate_insert/',views.estimate_ui,name='estimate_i'),
path('<int:id>/',views.estimate_ui,name='estimate_u'),
path('estimate_delete/<int:id>/',views.estimate_d,name='estimate_d'),
path('estimate_preview/<int:id>/',views.estimate_preview,name='estimate_v'),
]
I am matching these urls to the following code in views.py
def estimate_ui(request,id=0):
if request.method=="GET":
if id==0:
form=EstimateForm()
else:
obj_estimate=Estimate.objects.get(pk=id)
form=EstimateForm(instance=obj_estimate)
return render(request,"Invoices/estimate_ui.html",{'form':form})
else:
if id==0:
form=EstimateForm(request.POST)
else:
obj_estimate=Estimate.objects.get(pk=id)
form=EstimateForm(request.POST,instance=obj_estimate)
if form.is_valid():
form.save()
return redirect('/invoices/')
the below mentioned url is causing problem when I access it.
path('<int:id>/',views.estimate_ui,name='estimate_u'),
When I access I get the following error
NoReverseMatch at /invoices/status/3/
Reverse for 'estimate_u' with arguments '('',)' not found. 1 pattern(s) tried: ['estimate/(?P<id>[0-9]+)/$']
Request Method:
GET
Request URL:
http://127.0.0.1:8000/invoices/status/3/
Django Version:
3.1.4
Exception Type:
NoReverseMatch
Exception Value:
Reverse for 'estimate_u' with arguments '('',)' not found. 1 pattern(s) tried: ['estimate/(?P<id>[0-9]+)/$']
can anyone explain why is this happening. I am accessing index.html--> linked to move to status.html(it has link to move estimate.html)--> at estimate.html I have many steps its basically a workflow based application. I watched almost all url related videos at youtube, searched google but found nothing that could help. thanks
Error: NoReverseMatch at /myplaylists/
Reverse for 'create_playlist' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
My urls.py:
url(r'^create_playlist/$', views.create_playlist, name='create_playlist'),
On my index page, im trying to reference that url using :
Create playlist
If you are using namespacing in your application, you need to reference the namespace in your url template tag like so:
{% url 'name_of_namespace:name_of_view' %}
Trying to access part of code by get request and receiving this error
NoReverseMatch: Reverse for 'homepage' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] looked around for help and i think its that am missing some arguments.
here is request am using in my test
req = self.client.get('/password/reset/')
and the code it leads to is as:
class PasswordResetEmailView(FormView):
template_name = 'temp/password_reset.html'
form_class = PasswordResetForm
success_url = 'password_reset_ok'
def get(self, request, *args, **kwargs):
form = self.get_form(self.form_class)
return self.render_to_response(self.get_context_data(form=form))
any guidance ?
You ask specifically about "determining which arguments are missing", but should be irrelevant to your error.
Your error message states that it can't find any URL patterns matching the name "homepage", before attempting any argument matching. Therefore no URLs exist named "homepage" in your setup. If it was an argument mismatch, you'd see a list of named URLs in the error such as "tried X urls."
Either define a URL named home in your URLConf url(r'^home/$', 'home_view', name="homepage") or find the location that is calling reverse('homepage') and remove it. You will find this information in your traceback.
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 %}
I seem to have another problem with passing parameters in Django. I seem to get a Caught NoReverseMatch error.
Caught NoReverseMatch while rendering: Reverse for 'tiptop.views.service_order2' with arguments '('', 17L, 1)' and keyword arguments '{}' not found
It reaches the client_id and service_type but not the order_no. I am not so sure what is wrong but it complains of the order.pk argument.
#urls
(r'^quote/service_order/(?P<client_id>\d+)/(?P<order_no>\d+)/(?P<request_type>\d+)/$', views.service_order2),
#views.py
def service_order2(request, client_id = 0, order_no = 0, request_type = 1):
# A lot of code
order=request.session['order']
return render_to_response('service_step1__2nd.html', {'contacts':contacts, 'addresses':addresses, 'title':title, 'service_list':service_list, 'date_type':date_type, 'address_type':address_type, 'order':order}, context_instance = RequestContext(request))
This template contains the template tag link that is suppose to go to service_step1__2.html template
<input type="submit" value="Request Delivery" onclick="change_action('{% url tiptop.views.service_order2 order.pk client.pk 1 %}')"/>
Your order object does not have a pk value, for whatever reason - presumably it's a new unsaved instance. So it's passing an empty string as the first parameter to the URL, and is failing to match your service_order2 url which expects a number in that position.