我想从cms页面访问网址
from cms.models import Page
page = Page.objects.published()[3] #clinics page
print page.get_absolute_url()
但它显示了这个错误:
ImproperlyConfigured at /en/clinics/
The included urlconf urls doesn't have any patterns in it
诊所页面有效(admin + frontend),问题出在我试图调用get_absolute_url()
时
urls.py:
的一部分urlpatterns += i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
诊所/ urls.py:
from django.conf.urls import patterns, url
from clinics import views
urlpatterns = patterns('',
url(r'^$', views.clinic_list, name='clinic_list'),
)
答案 0 :(得分:1)
我找到了另一种方法,它可以工作。直接拨打reverse
路由的clinic_list
。我认为没有必要通过cms页面的方式。
from django.core.urlresolvers import reverse
print reverse('clinic_list')
答案 1 :(得分:0)
page = Page.objects.published()[3]
这不起作用,因为published
是模型BooleanField
中的Page
。
您想要做的是:
page = page.objects.get(pk=3) # At least if this pk is 3, check with your installation.
page.get_absolute_url()