我对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: []
知道为什么我会出现这个异常吗?
异常意味着 django 在其 urls 配置中找不到匹配项。
您是否在根urls.py
中添加了一些?发布文件。
也许您缺少在其中包含以下内容:
urls.py
urlpatterns = [
...
url(r'the_app_name/', include('the_app_name.urls')),
...
]
因此,您应该在名为set_device
的地方有一个接受"移动">作为参数的 url,如下所示
app_name = 'the_app_name'
urlpatterns = [
url(r'^my_url/(?P<type>(mobile|...))/$', my_view, name='set_device'),
...
我们应该认为它是在 CMS 中内置的还是您自己的?