在 Django 中使用 summernote 时出现 NoReverseMatch 错误
NoReverseMatch error when using summernote in Django
当我在django admin中点击添加按钮添加一些文章时,出现了这个错误。一些细节如下所示。
调试信息
NoReverseMatch at /admin/guitar/article/add/
Reverse for 'django_summernote-editor' with arguments '()' and keyword arguments '{'id': 'id_content'}' not found. 1 pattern(s) tried: ['$summernote/editor/(?P<id>.+)/$']
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/guitar/article/add/
Django Version: 1.8.6
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'django_summernote-editor' with arguments '()' and keyword arguments '{'id': 'id_content'}' not found. 1 pattern(s) tried: ['$summernote/editor/(?P<id>.+)/$']
Exception Location: C:\Python34\lib\site-packages\django\core\urlresolvers.py in _reverse_with_prefix, line 495
Python Executable: C:\Python34\python.exe
Python Version: 3.4.3
Python Path:
['D:\DemoGuitarProject',
'D:\DemoGuitarProject',
'C:\Windows\system32\python34.zip',
'C:\Python34\DLLs',
'C:\Python34\lib',
'C:\Python34',
'C:\Python34\lib\site-packages']
Server time: Sat, 14 Nov 2015 16:45:05 +0800
Error during template rendering
In template C:\Python34\lib\site-packages\django\contrib\admin\templates\admin\includes\fieldset.html, error at line 19
Reverse for 'django_summernote-editor' with arguments '()' and keyword arguments '{'id': 'id_content'}' not found. 1 pattern(s) tried: ['$summernote/editor/(?P<id>.+)/$']
9 {% for field in line %}
10 <div{% if not line.fields|length_is:'1' %} class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
11 {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
12 {% if field.is_checkbox %}
13 {{ field.field }}{{ field.label_tag }}
14 {% else %}
15 {{ field.label_tag }}
16 {% if field.is_readonly %}
17 <p>{{ field.contents }}</p>
18 {% else %}
19
{{ field.field }}
20 {% endif %}
21 {% endif %}
22 {% if field.field.help_text %}
23 <p class="help">{{ field.field.help_text|safe }}</p>
24 {% endif %}
25 </div>
26 {% endfor %}
27 </div>
28 {% endfor %}
29 </fieldset>
settings.py
"""
Django settings for DemoGuitarProject project.
Generated by 'django-admin startproject' using Django 1.8.6.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
MEDIA_URL = "media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ')7sn#y%9dgm!pxl#c$ws_jld!%2lbvj5tg*jlqnaelc)+$bp*%'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrap3',
'guitar',
'django_summernote',
)
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',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'DemoGuitarProject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'DemoGuitarProject.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
urls.py
urlpatterns = [
url(r'^$', 'guitar.views.home', name='home'),
url(r'^summernote/', include('django_summernote.urls')),
]
admins.py
from django.contrib import admin
from .models import Article, Category
from django_summernote.admin import SummernoteModelAdmin
class SomeModelAdmin(SummernoteModelAdmin):
pass
admin.site.register(Article,SomeModelAdmin)
admin.site.register(Category)
models.py
# coding:utf-8
from django.template.defaultfilters import slugify
from django.db import models
class Article(models.Model):
title = models.CharField(u'标题', max_length=256)
content = models.TextField(u'内容')
pub_date = models.DateTimeField(u'发表时间', auto_now_add=True, editable=True)
update_time = models.DateTimeField(u'更新时间',auto_now=True, null=True)
def __str__(self):
return self.title
class Category(models.Model):
name = models.CharField(max_length=128, unique=True)
def __str__(self):
return self.name
如果您包含上述网址,请确保它们不以美元结尾。
例如,而不是
url(r'^guitar/$', include('guitar.urls')),
应该是
url(r'^guitar/', include('guitar.urls')),
当我在django admin中点击添加按钮添加一些文章时,出现了这个错误。一些细节如下所示。
调试信息
NoReverseMatch at /admin/guitar/article/add/
Reverse for 'django_summernote-editor' with arguments '()' and keyword arguments '{'id': 'id_content'}' not found. 1 pattern(s) tried: ['$summernote/editor/(?P<id>.+)/$']
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/guitar/article/add/
Django Version: 1.8.6
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'django_summernote-editor' with arguments '()' and keyword arguments '{'id': 'id_content'}' not found. 1 pattern(s) tried: ['$summernote/editor/(?P<id>.+)/$']
Exception Location: C:\Python34\lib\site-packages\django\core\urlresolvers.py in _reverse_with_prefix, line 495
Python Executable: C:\Python34\python.exe
Python Version: 3.4.3
Python Path:
['D:\DemoGuitarProject',
'D:\DemoGuitarProject',
'C:\Windows\system32\python34.zip',
'C:\Python34\DLLs',
'C:\Python34\lib',
'C:\Python34',
'C:\Python34\lib\site-packages']
Server time: Sat, 14 Nov 2015 16:45:05 +0800
Error during template rendering
In template C:\Python34\lib\site-packages\django\contrib\admin\templates\admin\includes\fieldset.html, error at line 19
Reverse for 'django_summernote-editor' with arguments '()' and keyword arguments '{'id': 'id_content'}' not found. 1 pattern(s) tried: ['$summernote/editor/(?P<id>.+)/$']
9 {% for field in line %}
10 <div{% if not line.fields|length_is:'1' %} class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
11 {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
12 {% if field.is_checkbox %}
13 {{ field.field }}{{ field.label_tag }}
14 {% else %}
15 {{ field.label_tag }}
16 {% if field.is_readonly %}
17 <p>{{ field.contents }}</p>
18 {% else %}
19
{{ field.field }}
20 {% endif %}
21 {% endif %}
22 {% if field.field.help_text %}
23 <p class="help">{{ field.field.help_text|safe }}</p>
24 {% endif %}
25 </div>
26 {% endfor %}
27 </div>
28 {% endfor %}
29 </fieldset>
settings.py
"""
Django settings for DemoGuitarProject project.
Generated by 'django-admin startproject' using Django 1.8.6.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
MEDIA_URL = "media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ')7sn#y%9dgm!pxl#c$ws_jld!%2lbvj5tg*jlqnaelc)+$bp*%'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrap3',
'guitar',
'django_summernote',
)
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',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'DemoGuitarProject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'DemoGuitarProject.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
urls.py
urlpatterns = [
url(r'^$', 'guitar.views.home', name='home'),
url(r'^summernote/', include('django_summernote.urls')),
]
admins.py
from django.contrib import admin
from .models import Article, Category
from django_summernote.admin import SummernoteModelAdmin
class SomeModelAdmin(SummernoteModelAdmin):
pass
admin.site.register(Article,SomeModelAdmin)
admin.site.register(Category)
models.py
# coding:utf-8
from django.template.defaultfilters import slugify
from django.db import models
class Article(models.Model):
title = models.CharField(u'标题', max_length=256)
content = models.TextField(u'内容')
pub_date = models.DateTimeField(u'发表时间', auto_now_add=True, editable=True)
update_time = models.DateTimeField(u'更新时间',auto_now=True, null=True)
def __str__(self):
return self.title
class Category(models.Model):
name = models.CharField(max_length=128, unique=True)
def __str__(self):
return self.name
如果您包含上述网址,请确保它们不以美元结尾。
例如,而不是
url(r'^guitar/$', include('guitar.urls')),
应该是
url(r'^guitar/', include('guitar.urls')),