django-urls

ValueError when getting objects by id

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 09:01:28
问题 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 input the below codes in views. Views def cribdetail(request, meekme_id): post=Meekme.objects.get(id=meekme_id) return render_to_response('postdetail.html',{'post':post, 'Meekme':Meekme},context_instance=RequestContext(request)) Urlconf url(r'^cribme/(?P<meekme_id>)\d+/$', 'meebapp.views.cribdetail', name='cribdetail'), In template: <a href="{% url cribdetail post.id %}">{{

404 error in django when visiting / Runserver returns no errors though

纵饮孤独 提交于 2019-12-02 08:11:38
When I syncdb and runserver everything works correctly in Django, but when I try to visit the webpage that it is on http://127.0.0.1:8000/ it returns a 404 error. Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/ Using the URLconf defined in MyBlog.urls, Django tried these URL patterns, in this order: ^admin/ The current URL, , didn't match any of these. The strange part is that when I visit /admin on the page it works fine. I dont understand what is failing here. Any help would be awesome! You need an URL route to the homepage. The urlpatterns variable in MyBlog

Django: UnboundLocalError: local variable 'company' referenced before assignment

谁说我不能喝 提交于 2019-12-02 05:19:00
I am trying to make a url field in my detail view by passing two primary key in it... This is what I have done in urls.py: url(r'^company/(?P<pk1>\d+)/groupdetail/(?P<pk2>\d+)/$',views.group1DetailView.as_view(),name='groupdetail'), And in my views: def get_object(self): pk1 = self.kwargs['pk1'] pk2 = self.kwargs['pk2'] company = get_object_or_404(company, pk=pk1) group1 = get_object_or_404(group1, pk=pk2) return group1 I am getting error in this line: company = get_object_or_404(company, pk=pk1) And in my group1 list view I have done this: <a href="{% url 'accounting_double_entry:groupdetail'

TypeError when concatenating django.test.LiveServerTestCase's live_server_url with another string

試著忘記壹切 提交于 2019-12-01 23:47:36
Whenever I try to construct a string based on self.live_server_url , I get python TypeError messages. For example, I've tried the following string constructions (form 1 & 2 below), but I experience the same TypeError . My desired string is the Live Server URL with "/lists" appended. NOTE: the actual test does succeed to create a server and I can manually access the server, and more specifically, I can manually access the exact URL that I'm trying to build programmatically (e.g. 'http://localhost:8081/lists '). TypeError s occur with these string constructions. # FORM 1 lists_live_server_url =

NoReverseMatch - Django 1.7 Beginners tutorial

末鹿安然 提交于 2019-12-01 22:15:39
问题 I am following the begginers tutorial in Django 1.7.1 and am getting this error Reverse for 'vote' with arguments '(5,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] `poll\templates\poll\detail.html, error at line 12` after a bit of research I found people asking similar question and someone suggested that they should remove the cash $ from the general url, because the urlloader just takes the empty string, while this doesn't gives me the error No Reverse Match, it messes

NoReverseMatch - Django 1.7 Beginners tutorial

荒凉一梦 提交于 2019-12-01 21:39:25
I am following the begginers tutorial in Django 1.7.1 and am getting this error Reverse for 'vote' with arguments '(5,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] `poll\templates\poll\detail.html, error at line 12` after a bit of research I found people asking similar question and someone suggested that they should remove the cash $ from the general url, because the urlloader just takes the empty string, while this doesn't gives me the error No Reverse Match, it messes everything else up, whenever I try to reach any other url it redirects me to the main url, while without

Django URL Pattern For Integer

随声附和 提交于 2019-12-01 16:52:15
I'm new to Python and Django. I added a URLPattern into urls.py as below: url(r'^address_edit/(\d)/$', views.address_edit, name = "address_edit"), I want my url accept a parameter of an integer with variable length, E.g. 0, 100, 1000, 99999, for the "id" of a db table. However I found that I only accept only one digits in above pattern. If i pass a integer not 1 digit only (e.g. 999999), it show an error Reverse for 'address_edit' with arguments '(9999999,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['address_book/address_edit/(\\d)/$'] How do I construct the URL Pattern that

Redirect any urls to 404.html if not found in urls.py in django

半世苍凉 提交于 2019-12-01 16:08:19
How can I redirect any kind of url patterns to a created page "404.html" page if it doesn't exist in the urls.py rather than being shown the error by django. moonstruck Make a view that'll render your created 404.html and set it as handler404 in urls.py. handler404 = 'app.views.404_view' Django will render debug view if debug is enabled. Else it'll render 404 page as specified in handler404 for all types of pages if it doesn't exist. Django documentation on Customizing error views . Check this answer for a complete example. kartikmaji In your views.py, just add the following code (No need to

Django URL Pattern For Integer

隐身守侯 提交于 2019-12-01 14:44:01
问题 I'm new to Python and Django. I added a URLPattern into urls.py as below: url(r'^address_edit/(\d)/$', views.address_edit, name = "address_edit"), I want my url accept a parameter of an integer with variable length, E.g. 0, 100, 1000, 99999, for the "id" of a db table. However I found that I only accept only one digits in above pattern. If i pass a integer not 1 digit only (e.g. 999999), it show an error Reverse for 'address_edit' with arguments '(9999999,)' and keyword arguments '{}' not

Passing a list through url in django

吃可爱长大的小学妹 提交于 2019-12-01 14:14:32
I want to pass a list through the url. But when i tried, i got some errors. So how can i do that. Somebody please help me.. this is my view def add_student(request): if request.method == 'POST': student_list = [] student_name = request.POST.getlist('student_name') student_phone = request.POST.getlist('student_phone') zipped = zip(student_name,student_phone) for student_name,student_phone in zipped: student_object = Student( student_name=student_name, student_phone=student_phone ) student_object.save() student_list.append(student_object.id) return HttpResponseRedirect(reverse('students:view