urlconf

Non-capturing optional URL elements in Django

非 Y 不嫁゛ 提交于 2021-02-19 05:34:56
问题 I'm using Django and would like to match the URLs domain.com/w and domain.com/words . I have a configuration line of the form: url(r'^w(ords)?$', 'app_name.views.view_words') view_words takes only one parameter ( request ), but it seems that Django captures the (ords) part of the regular expression and passes it to the view. When I remove (ords) from the regex and access domain.com/w , it works properly. The Django documentation and similar StackOverflow questions cover how to capture

Non-capturing optional URL elements in Django

删除回忆录丶 提交于 2021-02-19 05:34:37
问题 I'm using Django and would like to match the URLs domain.com/w and domain.com/words . I have a configuration line of the form: url(r'^w(ords)?$', 'app_name.views.view_words') view_words takes only one parameter ( request ), but it seems that Django captures the (ords) part of the regular expression and passes it to the view. When I remove (ords) from the regex and access domain.com/w , it works properly. The Django documentation and similar StackOverflow questions cover how to capture

Django Error passing URL argument from Template to View: NoReverseMatch Reverse not found. 1 pattern(s) tried

女生的网名这么多〃 提交于 2020-01-14 06:52:10
问题 I am trying to pass configure a URL like so: /details/12345 Template HTML: <div class="row"> {% if article_list %} {% for article in article_list %} <div> <h2>{{ article.title }}</h2> <p>{{ article.body }}</p> <p><a class="btn btn-default" href="{% url 'details' article.id %}" role="button">View details »</a></p> </div><!--/.col-xs-6.col-lg-4--> {% endfor %} {% endif %} </div><!--/row--> urls.py (full): from django.conf import settings from django.conf.urls import include, url from django

Django: variable parameters in URLconf

耗尽温柔 提交于 2019-12-22 08:46:15
问题 I've been looking for this question and couldn't find any, sorry if it's duplicated. I'm building some kind of ecommerce site, similar to ebay. The problem i have arise when i'm trying to browse through "categories" and "filters". For example. You can browse the "Monitor" category. That will show you lots of monitors, and some filters (exactly the same as ebay) to apply them. So, you go to "monitors", then you have filters like: Type: LCD - LED - CRT Brand: ViewSonic - LG - Samsung Max

Django URLS, using a ? in the URL

我只是一个虾纸丫 提交于 2019-12-19 07:10:09
问题 I am trying to do some Django URL matching. i want a few urls where i have http://mysite.com/base?sort=type1/, http://mysite.com/base?sort=type2/, etc. I can't figure out how to URL match these expressions: I'm very new to Django and never used Reg Ex before. What I have for urls.py in my "base" application is: url(r'^$','base.views.main, name='main'), I can't figure out what to put to match my urls with question marks. I'm trying something like url(r'^?sort=popular/$', 'base.views.main

Django Url, Slug for Detail Page

a 夏天 提交于 2019-12-17 23:26:22
问题 I'm having trouble configuring my url to display a detail view. Clicking on this link: <a href='{% url blog_detail blog.slug %}'>{{ blog.name }}</a> shows blog.html , when I thought it would show blog-detail.html . There are no errors and the browser bar says: example.com/blog/the-slug , yet still displays the html from blog.html , not blog-detail.html . Any ideas why? Thanks for your ideas. url: url(r'^blog/', 'myapp.views.blog', name='blog'), url(r'^blog/(?P<slug>[\w-]+)/$', 'myapp.views

Django, name parameter in urlpatterns

那年仲夏 提交于 2019-12-17 22:33:48
问题 I'm following a tutorial where my urlpatterns are: urlpatterns = patterns('', url(r'^passwords/$', PasswordListView.as_view(), name='passwords_api_root'), url(r'^passwords/(?P<id>[0-9]+)$', PasswordInstanceView.as_view(), name='passwords_api_instance'), ...other urls here..., ) The PasswordListView and PasswordInstanceView are supposed to be class based views. I could not figure out the meaning of the name parameter. Is it a default parameter passed to the view? 回答1: No. It is just that

Django: GET css returns 404?

不羁岁月 提交于 2019-12-12 08:59:46
问题 I am developing a Django site and after a series of edits I ran my server again when suddenly - no css! The server still displays the html site, of course, but the css all across the site is throwing a 404 error. My static files information in my settings.py wasn't edited at all: import os # hack to accommodate Windows CURRENT_PATH = os.path.abspath(os.path.dirname(__file__).decode('utf-8')).replace('\\', '/') STATIC_URL = '/static/' # Additional locations of static files STATICFILES_DIRS = (

Django: variable parameters in URLconf

百般思念 提交于 2019-12-05 12:22:27
I've been looking for this question and couldn't find any, sorry if it's duplicated. I'm building some kind of ecommerce site, similar to ebay. The problem i have arise when i'm trying to browse through "categories" and "filters". For example. You can browse the "Monitor" category. That will show you lots of monitors, and some filters (exactly the same as ebay) to apply them. So, you go to "monitors", then you have filters like: Type: LCD - LED - CRT Brand: ViewSonic - LG - Samsung Max Resolution: 800x600 - 1024x768 And those filters will be appended to the URL, following with the example,

Django: GET css returns 404?

无人久伴 提交于 2019-12-04 14:59:58
I am developing a Django site and after a series of edits I ran my server again when suddenly - no css! The server still displays the html site, of course, but the css all across the site is throwing a 404 error. My static files information in my settings.py wasn't edited at all: import os # hack to accommodate Windows CURRENT_PATH = os.path.abspath(os.path.dirname(__file__).decode('utf-8')).replace('\\', '/') STATIC_URL = '/static/' # Additional locations of static files STATICFILES_DIRS = ( os.path.join(CURRENT_PATH, 'static'), ) My base template does a simple call for the file based on the