FAQ Database Discussion Community


Django Url does not work

django,django-templates,django-views,django-urls
I am trying to obtain a url to a view that renders an image so I can use it in an img tag with href. But my {% url viewname object_id %} is not working. Here are the specifics: my urls.py: hydrourlpatterns = patterns('', url(r'^graphs/$','hydro.views.graphs',name='graphs'), url(r'^graphs/new/$', 'hydro.views.add_graph', name='add_graph'), url(r'^graphs/(?P<graph_id>\d+?)/$', 'hydro.views.single_graph',...

How to use reverse() in django on included URLs?

python,django,django-templates,django-urls
My urls.py looks roughly like this: ... url(r'^advance-day/$', 'mafia.views.advance_day', name='advance_day'), url(r'^form/', include(form_urls)), ... I recently moved things to a separate form_urls.py for form URLs because there are a lot of forms, and I want to not have them in the way. However, I then can't figure out how to use...

urls django, NoReverseMatch

django,django-templates,reverse,django-urls
I have this error and I don't know it's origin : NoReverseMatch at /PROJETTEST/rec Reverse for 'myp' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['(?P\w+)$'] url(r'^allp$', allp.as_view(), name="allp"), url(r'^allp/(?P<slug>[^/]+)$',ficheP.as_view(), name="ficheP"), url(r'^(?P<namep>\w+)$','myp', name="myp"), url(r'^(?P<namep>\w+)/members$','members', name="members"), url(r'^(?P<namep>\w+)/rec','rec', name="rec"), <a href="{% url 'myp' p.name %}" role="button">Gen</a>...

DJango URL Reverse is killing me

python,django,django-urls
Here is my urls.py from django.conf.urls import include, url from django.contrib import admin from common.views import HomeView, LoadingSchoolView, ProcessSchoolView urlpatterns = [ url(r'^$', HomeView.as_view(), name='Index'), url(r'^admin/', include(admin.site.urls)), url(r'^member/', include('member.urls', namespace='member')), url(r'^common/', include('common.urls', namespace='common')), In my common/urls.py from django.conf.urls import url from .views import QuerySchoolView urlpatterns = { url(r'^querySchool/(?P<q>[a-z]*)$',...

django does not match pattern called in template

python,regex,django,django-templates,django-urls
Iam trying to call {% url %} in a template to have dynamic links, but i get an error although the pattern should match. Here are my files: urls.py urlpatterns = [ url(r'^(?P<team_id>[0-9]+)/$', views.detail, name='detail'), url(r'^$', views.index, name='index'), ] template file {% for team in teams_list %} <li><a href="{% url...

Django multi tenancy

python,django,django-urls
Tl; dr: Is there a way to override the default behaviour of reverse? In my django project I have alot of urls such as url(r'^\w+/company/', include("company.urls", namespace="company")), Which allows for urls such as .../companyA/company/ .../companyB/company/ So that I can then use a custom middleware to modify the request to include...

How do I create pretty url from the GET parameters in Django?

python,django,forms,django-templates,django-urls
my query string is generated by a form with name and age, that looks something like this, www.example.com/?name=Martin&age=19&place=RU the form, <form action="" method="get"> Name: <input type="text" name="name"><br> Age: <input type="text" name="age"><br> Place <input type="text" name="place"><br> <input type="submit" value="Submit"> </form> and I want to make the submitted url to django to...

NoReverseMatch in Django with namespace

python,django,django-urls
I can't do a reverse in Django without throwing a NoReverseMatch, even though the pages will load if no reverse is done. Here is the relevant code: main/urls.py from django.conf.urls import patterns, include, url urlpatterns = patterns('', url(r'(^$)|(^admin/)',include('example_admin.urls',namespace='example_admin')), ) example_admin/urls.py from django.conf.urls import patterns, include, url from example_admin import views...

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

python,regex,django,django-urls
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.

adding parameter between URL in django

python,django,django-urls
I am a beginner in Django. I want to pass a parameter to a URL. Here is how I want the URL to look like: /category/<parameter>/add_page/ What is the regular expression for this url?...

Django urls.py only one app

python,django,django-urls
I just started playing with Django, I love it! I followed the tutorial from the Django documentation, but have the following question: I only have one app (polls), currently I always have localhost/polls/{urlname} Is there a way to remove the polls keyword? So people that go to localhost automatically go...

Django: how to pass an entire URL as a parameter inside the app URL?

python,django,django-views,django-urls
I am trying to pass an entire, full length/structure URL within my app as an argument inside the app's URL. For example, I want to be able to do something like: myapp.com/https://www.youtube.com/watch?v=dQw4w9WgXcQ so that I can take the URL entered after my app's home page and store it. However, I...

Url configuration in django always executs the same view

django,django-urls
I want to achieve the following behavior http://localhost/ runs index view in my app http://localhost/myview runs myview in my app So in main urls.py I have the following setup urlpatterns = [ url(r"^", include("myapp.urls")), url(r"^admin/", include(admin.urls)), ] and in myapp urls.py urlpatterns = [ url(r'$', "myapp.views.index"), url(r'myview/$', "myapp.views.myview") ] but...

reverse url of the blog article in template

django,django-templates,django-views,django-urls
{% url 'article' article.get_absolute_url %} wont' work as expected. Got error NoReverseMatch at /blog/ Url pattern is: url(r'^/(?P<slug>[-\w]+)-(?P<id>[-\d]+)/$', article, name='article'), where article is the function name....

Passing multiple values in a django url with dashes

django,django-views,django-urls
I am passing several values to a view through my url. Through some blind luck (read experienced debugging (: ) I fixed an issue I had where the view was interpreting the arguments in an unexpected fashion. The old url looked like: url(r'^explore/(?P<id>[\w\-]+)-(?P<region>[\w\-]+)-(?P<location_name>[-\w]+)-(?P<page>[\w\-]+)/$', 'project.apps.web_feed.views.display_feed', name='display_feed'), My display_feed view looked like...

Why won't HttpResponseRedirect update the URL?

django,django-views,django-urls
I want an optional slug in my applications's URLs, like how Stack Overflows does its URLs: http://stackoverflow.com/questions/<question_id>/<question_slug>, where <question_slug> is optional. That is, if you go to http://stackoverflow.com/questions/<question_id>, you'll be redirected to http://stackoverflow.com/questions/<question_id>/<question_slug> My urls.py: url(r'^myapp/(?P<thing_id>\d+)/edit_thing/$', views.edit_thing, name='edit-thing'),...

django can't find views…page not found error

python,django,django-views,django-urls
I am trying to print a response from the view.. but django shows the page not found error(404) My main project.urls are:- from django.conf.urls import patterns, include, url from django.contrib import admin from django.conf import settings from . import views urlpatterns = patterns('', # Examples: # url(r'^$', 'ultimatefinalblog.views.home', name='home'), #...

Having trouble using reverse()

python,django,django-urls
It feels like this is a simple problem but I am obviously missing something. url = reverse('specific', args=(var.pk,)) print(url) The error message i get is: Reverse for 'specific' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] Here are my urls: For myapp level urlpatterns =...

Django url name, some points I'm not sure about

django,django-urls
I'm following the steps of the django tutorial (part 4). And I'm here. There is this tag : {% url 'polls:vote' question.id %} which triggers the following line in the urls.py file : url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'), I want to be sure about these points : question.id is the value passed...

Django - Reverse with special character

python,django,django-templates,django-urls
When I want use argument with specials characters in reverse, I have this error : Reverse for 'l_s.views.my_pro' with arguments '()' and keyword arguments '{'namep': u'\xe9 \xe9 \xe9 sds ( \xe9zacd '}' not found. 1 pattern(s) tried: ['(?P\w+)$'] My View : def createPro(request): ... if form.is_valid() : name = form.cleaned_data["name"]...

Django urls.py not rendering correct template

python,django,templates,django-views,django-urls
This is my urls.py """s7h URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.8/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home...

Incorrect Django URL pattern match for 2 views with the same URL structure?

python,regex,django,django-urls
I have two url patterns in Django: urlpatterns += patterns('', url(r'^(?P<song_name>.+)-(?P<dj_slug>.+)-(?P<song_id>.+)/$', songs.dj_song, name='dj_song'), url(r'^(?P<song_name>.+)-(?P<artist_slug>.+)-(?P<song_id>.+)/$', songs.trending_song, name='trending_song'), ) When I visit a URL of the first pattern, it opens it correctly. However if I try and visit a URL of the second pattern, it tries to access the first view again....

Redirect URL with Argument in urls.py in Django 1.6.5

python,regex,django,django-urls
I recently switched from PHP to Django. My old site in PHP had Disqus integrated, when I migrated to new site, my blog urls changed from /blog/<year>/<month>/<slug> to /blog/<slug> All new comments are automatically taking the new url, but there are a lot of old links that are still in...

Is it possible to display a specific block from a template in django?

django,django-templates,django-views,django-urls,django-template-filters
Just like in html when you reference a section of a page with for instance<a href="#tips">Visit the Useful Tips Section</a> Would there be a way to do a similar thing in django if for instance I wanted to load my page straight to the tips section? I am extending base.html...

Images not displaying in Django 1.8

django,django-urls,django-media
In Django 1.8, I can upload images and they are saved on the path that they should, but when I add the path to template, the images are not displaying. I GET 200 http code for them in terminal server. Here are the relevant parts in settings.py: BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))...

Django url regex for username that accepts dots

regex,django,django-urls
I've been working with this url for username regex in Django for a while: url(r'^.../(?P<username>[-\w]+)/$' But now, I've got a strange case, sometimes Google answers with a username like this: luke.skywalker instead of lukeskywalker And it looks like my regex doesn't accept dots - I get a NoReverseMatcherror. Could someone...

Urls.py says my view is not defined (class based view)

django,django-urls,django-class-based-views
This is my urls.py for my project: from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^CMS/', include('CMSApp.urls')), url(r'^admin/', include(admin.site.urls)), ] and this is my urls.py for my app (CMSApp): from django.conf.urls import patterns, url urlpatterns = patterns( 'CMSApp.views', url(r'^users$', user_list.as_view()), url(r'^users/(?P<pk>[0-9]+)$', user_detail.as_view()), ) When I go...

Django Rest Framework - how to get Http header information in urls.py

python,django,django-views,django-rest-framework,django-urls
I am making a Django-based API and here is my urls.py. from django.conf.urls import include, url api_version = "v1" urlpatterns = [ url(r'^v1/', include( "api."+ api_version +".urls", namespace=api_version )), ] What I want to do is to retrieve API version from http accept header. I tried to use django.http.HttpRequest module,...

Django urls.py import not detecting

python,django,django-urls
I have a working api, and I am writing a UI to the API, as a separate application in the same project. My project urls.py looks like this from django.conf.urls import * import search from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^api/search$', search.validation), url(r'^ui', include('ui.urls')), ) My UI app's...

Django NoReverseMatch at /search/

django,django-urls
In a search form, users can choose some of the criteria (country, province and city) and post it the result to this view: def profile_search(request): if request.method == 'POST': form = AdvancedSearchForm(request.POST) if form.is_valid(): cd = form.cleaned_data country=cd['country'] province=cd['province'] city = cd['city'] params=( country, province, city ,) url = reverse('userprofile.views.profile_search_result',...

Django - parameters in view and not in urls

django,django-views,django-urls
I have this code : My view : members_pj(request,lesc,p,np): ... My templates : ... href="{% url 'members_pj' lesc p np %}" ... And my urls : url(r'^lesps/(?P<np>\w+)/members','members_pj', name="memberspj"), ... In fact, I don't want there are paramaters lesc and p in url... just np. How is it done? Thank's...

what is r in Django urls.py?

python,django,django-views,django-urls
Hi all I'm new to Django and wanna know this, The basic urls.py got statements like this, (r'^home/$', homeview), what is actually the r here? Whats the use of it? any resource to know about it? thank you....

How to run different Django apps on different subdomain

django,http,django-urls
Can it be possible to run Different Django apps on different Subdomains. For Example: For api.mydomain.com all request will be handled by my API app. But all other requests will be handled by my core app. I just want my API app to handle request made on api.mydomain.com. And all...

Django throwing error with '/' in url

django,django-urls
I have a urls.py in my django app as follows: url(r'^myurl/(?P<pid>.*)/(?P<qid>.*)/(?P<trantype>.*)$', views.MyView.as_view(), name='myurl'), Here the trantype parameter in the url can sometime have '/' from the data it gets. When such a scenario occurs, django throws me an error about the number of parameters being exceeded. How can i make...

How to reference to a Method inside a Class in urls.py

python,django,django-urls
I have this views.py from django.shortcuts import render from forms import ReferenceTableForm class ReferenceTable(object): def createReferenceTable(request): form = ReferenceTableForm() return render(request, "DataImport/createReferenceTable.html", {'form': form}) And this is my urls.py from django.conf.urls import patterns, include, url import views urlpatterns = patterns('', url(r'^$', views.createReferenceTable), ) But when I go to my url,...

DRF Browsable API only shows one Router

django,django-rest-framework,django-urls,python-3.4
Essentially, depending on the order in which I add my routes to my urlpatterns the browsable API will only show one router at a time. Here's my code: urls.py: from django.conf.urls import url, include from rest_framework import routers from .views import PlantViewSet # url router router = routers.DefaultRouter() router.register(r'plants', PlantViewSet,...