django-urls

Django can't find URL pattern

空扰寡人 提交于 2019-11-28 08:15:44
问题 I can't figure out why Django is unable to find the requested URL in my application. Here is the error code I get: Using the URLconf defined in littlelogsms.urls, Django tried these URL patterns, in this order: ^admin/ ^$ The current URL, success/, didn't match any of these. Here is my sms.urls.py file: from django.conf.urls import url from sms import views urlpatterns = [ url(r'^success/$', views.success, name='success'), url(r'^$', views.index, name='index') ] Here is the application urls

Django 2.0 path error ?: (2_0.W001) has a route that contains '(?P<', begins with a '^', or ends with a '$'

帅比萌擦擦* 提交于 2019-11-28 08:01:24
I'm new to Django and am trying to create the back end code for a music application on my website. I have created the correct view in my views.py file (in the correct directory) as shown below: def detail(request, album_id): return HttpResponse("<h1>Details for Album ID:" + str(album_id) + "</h1>") however, when creating the url or path for this (shown below) #/music/71/ (pk) path(r'^(?P<album_id>[0-9])/$', views.detail, name='detail'), I am experiencing a warning on my terminal stating: ?: (2_0.W001) Your URL pattern '^(?P<album_id>[0-9])/$' [name='detail'] has a route that contains '(?P<',

ImpropyConfiguredError about app_name when using namespace in include()

筅森魡賤 提交于 2019-11-28 06:40:05
I am currently trying out django. I use the namespace argument in one of my include() s in urls.py. When I run the server and try to browse, I get this error. File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\conf.py", line 39, in include 'Specifying a namespace in include() without providing an app_name ' django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead

Linking to the django admin site

北慕城南 提交于 2019-11-28 05:41:23
Very basic question, but I'm having trouble tracking down the answer on the web. I have a template, which I want to link to the django admin site (i.e. localhost:8000/admin). What is the code for this? I'm imagining something like <a href="{% url admin.site.root %}">link to admin panel</a> However, when I try the above snippet I get: Caught an exception while rendering: Reverse for 'project_name.django.contrib.admin.sites.root' with arguments '()' and keyword arguments '{}' not found. Help? Romain Try what Oggy is suggesting but then use ':' instead of '_' with the current Django: <a href="{%

How do I pass variables from one view to another and render with the last view's URL in Django?

老子叫甜甜 提交于 2019-11-28 04:16:56
问题 I'm building a student management system using Django. In this code, The user search for a student with the encrypted query name=StudentName&grade=Grade&id=StudentID&phone=ParentPhoneNumber&report=StudentReportNumber , that is extracted with the decrypt() method. Here are the two methods, the one which process the query and the one which shows the student profile. No data from the query is saved to the database, but will be used to query the student details from the database. def process

The current URL, app/, didn't match any of these

别说谁变了你拦得住时间么 提交于 2019-11-28 03:25:37
问题 I'm a newbie in Django and just started looking at it before a day by installing Django 1.10 on my local. I've followed all the instructions of this link https://docs.djangoproject.com/en/dev/intro/tutorial01/. However I'm continuously getting this error: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/polls/ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^admin/ The current URL, polls/, didn't match any of these. I've

How to identify an anchor in a url in Django?

余生长醉 提交于 2019-11-28 02:16:43
I'm doing a slideshow and each slide has a url format like this: articles/1234#slide=5 . I want to retrive the slide=5 part from the url in my url.py file and then pass it to the corresponding view function and finally, pass it to the template and render the right slide. The url settings is as follows: url(r'^(?P<article_id>\d+)#slide=(?P<current_slide>\d{1,2})$', 'articles.views.show_article') But it seems that it cannot get the current_slide variable from the url. I guess it has something to do with the anchor part cause it's not transferred to the server. But if I ignore the anchor part in

django url pattern for %20

半腔热情 提交于 2019-11-27 20:32:14
In Django what is the url pattern I need to use to handle urlencode characters such as %20 I am using (?P<name>[\w]+) but this only handles alphanumeric characters so % is causing an error I was able to make it work using the configuration given below. Check if it will suit your needs. (?P<name>[\w|\W]+) If you only want to allow space: (?P<name>[\w\ ]+) The best way to do that and allow others chars is using '\s' that is any spaces, tabs and new lines (?P<name>[\w\s]+) 来源: https://stackoverflow.com/questions/3675368/django-url-pattern-for-20

Page not found 404 on Django site?

£可爱£侵袭症+ 提交于 2019-11-27 20:28:14
问题 I'm following the tutorial on Django's site to create a simple poll app. However, Django is unable to resolve "//127.0.0.1:8000/polls" , even though I've defined the regex in mySite/urls.py. I'm doing this in a virtualenv, with the latest Django (1.7) installed. mySite/urls.py: from django.conf.urls import patterns, include, url from django.contrib import admin urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), url(r'^polls/', include('polls.urls')), ) mySite/polls/urls.py:

How do I redirect in Django with context?

和自甴很熟 提交于 2019-11-27 19:14:56
I have a view that validates and saves a form. After the form is saved, I'd like redirect back to a list_object view with a success message "form for customer xyz was successfully updated..." HttpResponseRedirect doesn't seem like it would work, because it only has an argument for the url, no way to pass dictionary with it. I've tried modifying my wrapper for object_list to take a dict as a parameter that has the necessary context. I the return a call to this wrapper from inside the view that saves the form. However, when the page is rendered, the url is '/customer_form/' rather than '/list