我对Mezzanine
并不陌生,并且在我的index.html
中无法使用查看移动网站选项时遇到了一些困难。
设置
在settings.py
中,我指定了以下内容:
INSTALLED_APPS = (
"newsletters",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.messages",
"django.contrib.contenttypes",
"django.contrib.redirects",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.sitemaps",
"django.contrib.staticfiles",
"mezzanine.boot",
"mezzanine.conf",
"mezzanine.core",
"mezzanine.generic",
"mezzanine.pages",
"mezzanine.blog",
"mezzanine.forms",
"mezzanine.accounts",
"mezzanine.mobile",
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"mezzanine.core.middleware.UpdateCacheMiddleware",
"mezzanine.core.request.CurrentRequestMiddleware",
"mezzanine.core.middleware.RedirectFallbackMiddleware",
"mezzanine.core.middleware.TemplateForDeviceMiddleware",
"mezzanine.core.middleware.TemplateForHostMiddleware",
"mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware",
"mezzanine.core.middleware.SitePermissionMiddleware",
"mezzanine.pages.middleware.PageMiddleware",
"mezzanine.core.middleware.FetchFromCacheMiddleware",
)
在我的index.html
中:
{% ifinstalled mezzanine.mobile %}
<span class="separator">|</span>
<a href="{% url "set_device" "mobile" %}?next={{ request.path }}">{% trans "View Mobile Site" %}</a>
{% endifinstalled %}
但是访问index.html
时出现此错误:
Reverse for 'set_device' with arguments '('mobile',)'
and keyword arguments '{}' not found.
0 pattern(s) tried: []
有什么主意为什么我会得到这个例外?
答案 0 :(得分:0)
该异常表示django在其url配置中找不到匹配项。
您是否在根urls.py
中添加了一些?发布文件。
也许您缺少包含这样的内容:
urls.py
urlpatterns = [
...
url(r'the_app_name/', include('the_app_name.urls')),
...
]
因此,您应该在一个名为set_device
的网址中接受'mobile'作为参数,类似这样的
app_name = 'the_app_name'
urlpatterns = [
url(r'^my_url/(?P<type>(mobile|...))/$', my_view, name='set_device'),
...
我们应该假设它是在CMS中构建的还是您自己的?