shelbydz
shelbydz

Reputation: 533

Django 1.5 The included urlconf doesn't have any patterns in it

Putting together a django application (my first django/python anything). I have some url patterns in another file in my application/urls.py. But when I start up and try to navigate to anything, I get The included urlconf module 'finances.urls' from '~/Development/PFM/finances/urls.py' doesn't have any patterns in it

I read on another post, here

that there's a potential issue with reverse lookup in the views. I'm just using generic Class-based views and one custom view, so I'm not sure where to start. Here's the code:

PFM/urls.py:

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
                       url(r'^finances/', include('finances.urls')),
                       # Examples:
                       # url(r'^$', 'PFM.views.home', name='home'),
                       # url(r'^PFM/', include('PFM.foo.urls')),

                       # Uncomment the admin/doc line below to enable admin documentation:
                       # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

                       # Uncomment the next line to enable the admin:
                       url(r'^admin/', include(admin.site.urls)),
)

PFM/finances/urls.py:

from django.conf.urls import patterns, url
from finances import views

urlpatterns = patterns
('',
    url(r'^$', views.ListView.as_view(), name='index'),
    url(r'^(P<pk>\d+/$)', views.TransactionList, name='detail'),  # transaction list
    url(r'^/account/(P<pk>\d+)/$', views.AccountList.as_view(), name='detail'),  # account detail
    url('/account/create/', views.account, name='create'),  # account create
    url(r'^/account/update/(P<pk>\d+)/$', views.AccountUpdate.as_view(), name='update'),  # account update
    url(r'^/account/delete/(P<pk>\d+)/$', views.AccountDelete.as_view(), name='delete'),  # account delete
 )

finances/models.py (in case it's needed)

#views for Account
class AccountList(DetailView):
    model = Account
    object_id = Account.pk


class AccountUpdate(UpdateView):
    model = Account
    object_id = Account.pk


class AccountDelete(DeleteView):
    model = Account
    object_id = Account.pk
    post_delete_redirect = "finances/"


#create form/view for Account
def account(request):
    if request.method == 'POST':
        form = AccountForm(request.POST)
        if form.is_valid():
            #save the data?
            Account.save()
            return HttpResponseRedirect('/index.html')
        else:
            form = AccountForm()

        return render(request, 'account_create.html', {
            'form': form,
        })


#views for Transactions
class TransactionList(ListView):
    template_name = "finances/index.html"

    def get_queryset(self):
        return Transaction.objects.order_by('-due_date')

Any help is appreciated. thx

Upvotes: 1

Views: 4756

Answers (2)

SaeX
SaeX

Reputation: 18711

Since this question was the first one popping up in Google, I thought I'd add.

For me the problem was due to an improperly configured django-debug-toolbar. See following question: ImproperlyConfigured: The included urlconf <project>.urls doesn't have any patterns in it

Using Django 1.6.

Upvotes: 3

karthikr
karthikr

Reputation: 99640

Fix the syntax:

urlpatterns = patterns('',
    url(r'^$', views.ListView.as_view(), name='index'),
    url(r'^(P<pk>\d+/$)', views.TransactionList, name='detail'),  # transaction list
    url(r'^/account/(P<pk>\d+)/$', views.AccountList.as_view(), name='detail'),  # account detail
    url('/account/create/', views.account, name='create'),  # account create
    url(r'^/account/update/(P<pk>\d+)/$', views.AccountUpdate.as_view(), name='update'),  # account update
    url(r'^/account/delete/(P<pk>\d+)/$', views.AccountDelete.as_view(), name='delete'),  # account delete
 )

the \n after patterns was the issue

Upvotes: 2

Related Questions