The included urlconf xxxx.urls doesn't have any patterns in it
Question: I want to get an url in a modelform class. I have seen in [The included
urlconf manager.urls doesn't have any patterns in
it](http://stackoverflow.com/questions/6482573/the-included-urlconf-manager-
urls-doesnt-have-any-patterns-in-it). But **reverse_lazy** function not work
for my case.  

My case:  
  

**captchahelper** is an **app** in **root**.  

**root urlpatterns (urls.py under root project):**

    
    
    urlpatterns = patterns("",
        .....
        # captcha
        url(r'^captcha/', include('captchahelper.urls')),
        .....
    }
    

**captcha urlpatterns(urls.py under captchahelper project):**

    
    
    urlpatterns = patterns('',
        url(r'^$', views.captcha , name="views_captcha"),
        url(r'^refresh/$', views.refresh , name="views_refresh_captcha"),
    )
    

  
**view.py under captchahelper project**

    
    
    def captcha(request):
        .....
        return HttpResponse(captcha.gen_img_by_code(code),'image/jpeg')
    

get:  
  

    
    
    class CaptchaForm(forms.ModelForm):
        .....
        captcha = Captcha()
        encoded = captcha.get_encrypt_code()
        captcha_image = urlresolvers.reverse_lazy('views_captcha') + '?encoded='+encoded
        .....
        def clean_captcha_text(self):
            ....
    

  
turn out error:  
/account/signup/ is current url(also include in root.urls),when a visitor
views this page,above class will be init in the corresponding view function.

    
    
    ImproperlyConfigured at /account/signup/
    The included urlconf root.urls doesn't have any patterns in it
    
    
    D:\Python27\lib\site-packages\django\core\urlresolvers.py in reverse
        return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) ...
     ▼ Local vars
        Variable    Value
        ns_pattern  
        ''
        viewname    
        'views_captcha'
        args    
        []
        current_app 
        None
        prefix  
        u'/'
        parts   
        ['views_captcha']
        resolver    
        <RegexURLResolver root.urls (None:None) ^/>
        kwargs  
        {}
        path    
        []
        resolved_path   
        []
        urlconf 
        'root.urls'
        view    
        'views_captcha'
    

I just feel django is so complex ,because I come from ASP MVC3.I can easy
generate an url with querystring from a statement like
`Url.Action("CaptchaController", "CaptchaView", new { encoded = "encoded"})`
in MVC3.But If I want to generate a url with querystring in django, the code
will be `reverse('captcha') + '?encoded=' + encoded`.It is really ugly....  


Answer: You are calling the class, not the def method itself in your urls file. Your
project seems a little odd, since most files have a `*.py` ending, but here's
an example from a project I'm already using:

    
    
    urls.py
    ...
    url(r'^getCustomerData/$', views.getCustomerData),
    ...
    

and in `views.py,

    
    
    from app.models import Customer
    
    def getCustomerData(request):
    //process and return
    

So for you, I'd suggest changing your url resolver from

    
    
    url(r'^$', views.captcha , name="views_captcha"),
    url(r'^refresh/$', views.refresh , name="views_refresh_captcha")
    

to

    
    
    url(r'^$', views.captcha.CAPTCHA_HANDLER_DEF , name="views_captcha"),
    url(r'^refresh/$', views.captcha.refresh , name="views_refresh_captcha")
    

and define those two functions within captcha.

