django-urls

Django optional url parameters

橙三吉。 提交于 2019-11-26 06:04:41
问题 I have a Django URL like this: url( r\'^project_config/(?P<product>\\w+)/(?P<project_id>\\w+)/$\', \'tool.views.ProjectConfig\', name=\'project_config\' ), views.py: def ProjectConfig(request, product, project_id=None, template_name=\'project.html\'): ... # do stuff The problem is that I want the project_id parameter to be optional. I want /project_config/ and /project_config/12345abdce/ to be equally valid URL patterns, so that if project_id is passed, then I can use it. As it stands at the

Django URLs TypeError: view must be a callable or a list/tuple in the case of include()

半城伤御伤魂 提交于 2019-11-26 00:24:01
问题 After upgrading to Django 1.10, I get the error: TypeError: view must be a callable or a list/tuple in the case of include(). My urls.py is as follows: from django.conf.urls import include, url urlpatterns = [ url(r\'^$\', \'myapp.views.home\'), url(r\'^contact/$\', \'myapp.views.contact\'), url(r\'^login/$\', \'django.contrib.auth.views.login\'), ] The full traceback is: Traceback (most recent call last): File \"/Users/alasdair/.virtualenvs/django110/lib/python2.7/site-packages/django/utils

What is a NoReverseMatch error, and how do I fix it?

最后都变了- 提交于 2019-11-25 21:49:38
问题 I have some code and when it executes, it throws a NoReverseMatch, saying: NoReverseMatch at /my_url/ Reverse for \'my_url_name\' with arguments \'()\' and keyword arguments \'{}\' not found. n pattern(s) tried: [] What does this mean, and what can I do about it? 回答1: The NoReverseMatch error is saying that Django cannot find a matching url pattern for the url you've provided in any of your installed app's urls. The NoReverseMatch exception is raised by django.core.urlresolvers when a