0

I'm running through a basic project using Django 1.8 and I'm not sure if I am missing something in the documentation or have just misunderstood it.

I am having a problem with urls.py recognizing the correct url patterns. I am using This section of the Django documentation for examples.

My project directory structure is:

integrations 
  |--integrations
           |--- migrations
                    |-- ....
           |-- __init__.py
           |-- admin.py
           |-- models.py
           |-- settings.py
           |-- urls.py
           |-- views.py
           |-- wsgi.py
  |-- templates
           |-- ....
  |-- manage.py

Specifically, contents of urls.py is:

from django.conf.urls import include, url
from django.contrib import admin
from . import views

urlpatterns = [
    url(r'^wsa/', views.index, name='index'),
    url(r'^(?P<customer_id>[0-9]+)/$', views.address_detail, name='address_detail'),
    url(r'^admin/', include(admin.site.urls)),
]

As you can see, I have wsa listed as a url pattern in this file. Based upon the documentation referred to above, this should be eliminated and instead be url(r'^$', views.index, name='index'),

The documentation also shows a different directory structure with, what appears to be a root urls.py in the root directory alongside manage.py. This is where the documentation indicates I would put my wsa pattern and include in the child urls.py; however when I do so, that file is not read and instead my url patterns begin to fail:

Using the URLconf defined in integrations.urls, Django tried these URL patterns, in this order:
^$ [name='index']
The current URL, wsa/, didn't match any of these.

Corrosponding url.py files that cause failure:

urls.py:

from django.conf.urls import include, url
from django.contrib import admin   

urlpatterns = [      
    url(r'^wsa/', include('integrations.urls')),
    url(r'^admin/', include(admin.site.urls)),
]

integrations\urls.py:

from django.conf.urls import include, url
from django.contrib import admin
from . import views

urlpatterns = [
    url(r'^$', 'views.index', name='index'),      
]

What am I missing?

1 Answer 1

1

You've misunderstood a few things here.

The "integrations" subdirectory is not supposed to contain model or view code. It is where your settings and wsgi files go, and also the main urls.py. That is the file referred to in the documentation.

Your actual code should go into a new app, let's say "wsa", created with ./manage.py startapp wsa. That's where you put the models, admin, and views files, and also the subsidiary urls.py. So your main urls would now contain include('wsa.urls').

Sign up to request clarification or add additional context in comments.

1 Comment

I figured I had missed something - Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.