django-urls

Reverse for 'todo-user' with arguments '('',)' not found. 1 pattern(s) tried

我们两清 提交于 2020-01-06 08:43:12
问题 I am trying to add an user when clicking on a link but I have the following error : Reverse for 'todo-user' with arguments '('',)' not found. 1 pattern(s) tried: ['todo/(?P[^/]+)/$'] My views.py def todo_user(request, todo_id): todo.username.add(request.user) todo.save() return render(request, '/') Template <a href="{% url 'todo-user' todo.id %}"></a> Urls.py path('validate/<todo_id>/', views.todo_user, name='todo-user), Views.py for the template render : def home(request, token): todo

Cannot access rosetta

筅森魡賤 提交于 2020-01-06 06:08:05
问题 Versions: Python 3.5.1 Django 1.10 django-rosetta 0.7.13 The installation guide tells you to add the following to your project's settings.py : from django.conf import settings if 'rosetta' in settings.INSTALLED_APPS: urlpatterns += patterns('', url(r'^rosetta/', include('rosetta.urls')), ) However, this just results in an error: NameError: name 'patterns' is not defined 回答1: Searching for that problem reveals that one apparently has to import it: from django.conf.urls import patterns But

Cannot access rosetta

こ雲淡風輕ζ 提交于 2020-01-06 06:08:02
问题 Versions: Python 3.5.1 Django 1.10 django-rosetta 0.7.13 The installation guide tells you to add the following to your project's settings.py : from django.conf import settings if 'rosetta' in settings.INSTALLED_APPS: urlpatterns += patterns('', url(r'^rosetta/', include('rosetta.urls')), ) However, this just results in an error: NameError: name 'patterns' is not defined 回答1: Searching for that problem reveals that one apparently has to import it: from django.conf.urls import patterns But

NoReverseMatch at / Reverse for 'password_change_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

安稳与你 提交于 2020-01-05 08:34:06
问题 my views part: @login_required def password_change(request, template_name='register.html', password_change_form=PasswordChangeForm,): if post_change_redirect is None: post_change_redirect = reverse('student:login') else: post_change_redirect = reverse_url(post_change_redirect) if request.method == 'POST': form = password_change_form(user=request.user, data=request.POST) if form.is_valid(): form.save() update_session_auth_hash(request, form.user) return HttpResponseRedirect(post_change

Getting Objects by id in Django

丶灬走出姿态 提交于 2020-01-05 08:29:31
问题 I'm trying to get data by id in my django app. The problem is that I don't know the kind of id the user will click on. I tried adding the below code in my views but I'm getting this error: ValueError at /findme/ invalid literal for int() with base 10: 'id' Request Method: GET Request URL: http://127.0.0.1:8000/findme/ Django Version: 1.4 Exception Type: ValueError Exception Value: invalid literal for int() with base 10: 'id' Exception Location: C:\Python27\lib\site-packages\django\db\models

Can any one explain how can i pass arg or kwargs from redirect to another view?

亡梦爱人 提交于 2020-01-05 05:27:54
问题 I am trying to let the manager of a site I'm developing send mail to the members and send get a confirmation page. The send mail is working and sending the mail OK, but in the confirmation i want him to get the the list of people he sent the mail to. So, i need to send the users_list from one function (view) to the other in the directs and read it in the other view sending it to render_to_response. I've read a lot and tried reverse and many other things i read over the web but can't seem to

How to Deal with Namespacing URLs in a Reusable Django App

霸气de小男生 提交于 2020-01-05 04:10:34
问题 I have been struggling with reversing URLs with a reusable Django app. Here's the basic layout of my problem. Reusable App: In the urls.py file it has the following pattern: url(r'^object-list/$', ObjectListView.as_view(), name='object-list') Somewhere in the reusable app's views.py , there is the following reverse call: reverse('object-list') My Project: In the project where I want to use this app, I have another conflicting view name, so I namespace the app's URLs like so: url(r'^app-stuff/

DeleteView with 2 arguements post and user

旧时模样 提交于 2020-01-03 04:25:27
问题 I have a delete view with 2 conditions "post" and "user". The user requirement is fulfilled by self.object.user = self.request.user and post requirement is fulfilled by slug = self.kwargs['slug'] (I think this may be the culprit) Are my views correct? I am new to python please forgive any silly mistakes. Views.py class ProofDelete(LoginRequiredMixin, DeleteView): model = Proof def delete(self, *args, **kwargs): return super().delete(*args, **kwargs) def get_success_url(self, *args, **kwargs):

Django url templatetag (but not reverse() ) error: Caught NoReverseMatch while rendering

心已入冬 提交于 2020-01-02 01:20:12
问题 I'm trying to use the url template tag as such: {% url all-labs-map %} but when i view the page, i get this error: Caught NoReverseMatch while rendering: Reverse for 'all-labs-map' with arguments '()' and keyword arguments '{}' not found. When I use the template tag like this: {% url gmaps.views.all_labs %} It works just fine. Here's the URL conf: urlpatterns = patterns('gmaps.views', url(r'^lab_list/$', 'all_labs', name="all-labs-map" ), ) I tried using the django shell to see if there was a

Get django object id based on model attribute

霸气de小男生 提交于 2019-12-31 17:58:35
问题 I have a basic model named "Places" which has this view: def view_index(request, place_name): The user will access that view with a URL like this one: http://server.com/kansas "kansas" is a value stored in a field named "name" inside the model "Places". The problem is that I can't figure out how to obtain the object id based just on the object name. Is there a way to do this? 回答1: Like this: place = Places.objects.get(name='kansas') print place.id 回答2: Since you only want id , you should only