Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6567393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:19:53+00:00 2026-05-25T14:19:53+00:00

I’m trying to use django’s reverse() function in definition of django form for my

  • 0

I’m trying to use django’s reverse() function in definition of django form for my custom widget, but am getting an error:

ImproperlyConfigured
The included urlconf urls doesn't have any patterns in it

Here is the code:

class WorkForm(forms.Form):
    # ...
    category = forms.ChoiceField(
        required=True,
        label=_('Category'),
        help_text=_('Select most appropriate category for your work.')
    )
    subcategory = forms.ChoiceField(
        widget=DependantChoiceWidget(
            default_value=_('Select category first'),
            data_source_url=reverse('works-json-categories'),
            # data_source_url='', -- it works this way
            depends_on='category_id'
        ),
        required=True,
        label=_('SubCategory'),
        help_text=_('Which subcategory suits your work best.')
    )

I am pretty sure, that my ‘works.urls’ is configured properly, since all other pages work as expected.

Is there a reason, why I cannot use reverse() in form definition? Does it have something to do with when this code runs? Is there a way to fix this, or the only choice here is to hardcode the URL?

Here is full error dump:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/works/add?category=1&subcategory=1

Django Version: 1.4 pre-alpha
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'social_auth',
 'sorl.thumbnail',
 'helpers',
 'users',
 'works',
 'debug_toolbar']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.transaction.TransactionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  89.                     response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in process_request
  67.             if (not _is_valid_path(request.path_info, urlconf) and
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in _is_valid_path
  164.         urlresolvers.resolve(path, urlconf)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  416.     return get_resolver(urlconf).resolve(path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  298.             for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
  328.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
  323.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/var/www/megenius/trunk/urls.py" in <module>
  27.     url(r'^works/', include('works.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
  24.         urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/var/www/megenius/trunk/works/urls.py" in <module>
  2. from works.views import *
File "/var/www/megenius/trunk/works/views.py" in <module>
  9. from works.forms import WorkForm
File "/var/www/megenius/trunk/works/forms.py" in <module>
  10. class WorkForm(forms.Form):
File "/var/www/megenius/trunk/works/forms.py" in WorkForm
  31.             data_source_url=reverse('works-json-categories'),
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
  473.                       (prefix, resolver.reverse(view, *args, **kwargs)))
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
  360.         possibilities = self.reverse_dict.getlist(lookup_view)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse_dict
  276.             self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _populate
  242.         for pattern in reversed(self.url_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
  332.             raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)

Exception Type: ImproperlyConfigured at /works/add
Exception Value: The included urlconf urls doesn't have any patterns in it
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:19:54+00:00Added an answer on May 25, 2026 at 2:19 pm

    The problem might be that the form is defined before the urls have been loaded.

    Django 1.4 will have a reverse_lazy feature that would solve this problem. You could implement it in your project yourself (see changeset 16121).

    Alternatively, you could set the widget in your forms __init__ method instead. Then the reverse call happens when the form is created, after the urls have loaded.

    class WorkForm(forms.Form):
        # ...
        subcategory = forms.ChoiceField(
            required=True,
            label=_('SubCategory'),
            help_text=_('Which subcategory suits your work best.')
        )
        def __init__(self, *args, **kwargs):
            super(WorkForm, self).__init__(*args, **kwargs)
            self.fields['subcategory'].widget=DependantChoiceWidget(
                default_value=_('Select category first'),
                data_source_url=reverse('works-json-categories'),
                depends_on='category_id'
            ),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.