Django1.5包含的urlconf在i中没有任何模式

2024-05-15 12:00:53 发布

您现在位置:Python中文网/ 问答频道 /正文

组装一个django应用程序(我的第一个django/python-anything)。我在应用程序的另一个文件中有一些url模式/网址.py. 但当我开始尝试导航到任何地方,我 包含的urlconf模块'财务.url'来自'~/Development/PFM/financials/网址.py“里面没有任何图案

我在另一篇文章中读到,here

视图中存在反向查找的潜在问题。我只是使用基于类的通用视图和一个自定义视图,所以我不确定从哪里开始。代码如下:

PFM公司/网址.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/财务/网址.py公司名称:

^{pr2}$

财务/模型.py(如果需要的话)

#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')

感谢任何帮助。 泰铢


Tags: thedjangopyformurlincludeadminrequest
2条回答

修复语法:

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
 )

在^{之后的\n就是问题所在

我以为这是我第一次提出这个问题。在

对我来说,这个问题是由于不正确配置django-debug-toolbar。 请参阅以下问题:ImproperlyConfigured: The included urlconf <project>.urls doesn't have any patterns in it

使用django1.6。在

相关问题 更多 >