反向' django_summernote-upload_attachment'未找到。 ' django_summernote-upload_attachment'不是有效的视图功能或模式名称
当我尝试添加帖子时,我会一直遇到此错误。 ,
“找不到'django_summernote-upload_attachment'的反向。
它说 ')“因为我已经做到了。
summernote/',include(' django_summernote.urls
from django.db import models
from django.contrib.auth.models import User
from django_summernote.widgets import SummernoteWidget, SummernoteInplaceWidget
CATEGORY = (
("Beginner", "Beginner"),
("Intermediate", "Intermediate"),
("Advanced", "Advanced"),
)
class Post(models.Model):
title = models.CharField(max_length=300, unique=True)
slug = models.SlugField(max_length=300, unique=True)
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='course_posts')
content = models.TextField()
# content = models.CharField(widget=SummernoteWidget())
category = models.CharField(max_length=25, choices=CATEGORY, default="Beginner")
created_at = models.DateField(auto_now_add=True)
class Meta:
ordering = ['-created_at']
def __str__(self):
return self.title
urls.py
from . import views
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
app_name = 'course_app'
urlpatterns = [
path('course/', views.PostList.as_view(), name='course'),
path('course/<slug:slug>/', views.PostDetail.as_view(), name='course_posts'),
path('summernote/', include('django_summernote.urls')),
path('editor/', include('django_summernote.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Views.py
from django.shortcuts import render
from django.views import generic
from .models import Post
class PostList(generic.ListView):
"""
Return all posts that are with status 1 (published) and order from the latest one.
"""
queryset = Post.objects.order_by('-created_at')
template_name = 'course.html'
class PostDetail(generic.DetailView):
model = Post
template_name = 'course_post.html'
def courses(request):
return render(request, 'course.html', {'navbar': 'courses'})
我尝试添加一个JPG文件作为附件,并且有效。这只是我有错误的“添加帖子”函数。
请帮忙!
I keep having this error when I try to add a post.
It says,
"Reverse for 'django_summernote-upload_attachment' not found. 'django_summernote-upload_attachment' is not a valid view function or pattern name."
I know this is not a matter of adding "path('summernote/', include('django_summernote.urls')" because I've already done that.
models.py
from django.db import models
from django.contrib.auth.models import User
from django_summernote.widgets import SummernoteWidget, SummernoteInplaceWidget
CATEGORY = (
("Beginner", "Beginner"),
("Intermediate", "Intermediate"),
("Advanced", "Advanced"),
)
class Post(models.Model):
title = models.CharField(max_length=300, unique=True)
slug = models.SlugField(max_length=300, unique=True)
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='course_posts')
content = models.TextField()
# content = models.CharField(widget=SummernoteWidget())
category = models.CharField(max_length=25, choices=CATEGORY, default="Beginner")
created_at = models.DateField(auto_now_add=True)
class Meta:
ordering = ['-created_at']
def __str__(self):
return self.title
urls.py
from . import views
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
app_name = 'course_app'
urlpatterns = [
path('course/', views.PostList.as_view(), name='course'),
path('course/<slug:slug>/', views.PostDetail.as_view(), name='course_posts'),
path('summernote/', include('django_summernote.urls')),
path('editor/', include('django_summernote.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
views.py
from django.shortcuts import render
from django.views import generic
from .models import Post
class PostList(generic.ListView):
"""
Return all posts that are with status 1 (published) and order from the latest one.
"""
queryset = Post.objects.order_by('-created_at')
template_name = 'course.html'
class PostDetail(generic.DetailView):
model = Post
template_name = 'course_post.html'
def courses(request):
return render(request, 'course.html', {'navbar': 'courses'})
I tried adding a jpg file as a attachment, and that works. It's just the "add post" function that I have an error with.
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我的URL的外观,并且运行良好,但是在我遇到相同的错误之前,我通过添加这两条路径 Summernote 和编辑来修复它。
This is how my URLs look like and it is working well, but before I was getting the same error and I fixed it by adding those two paths summernote and editor
似乎名称的模式'django_summernote-upload_attachment'在您的urlpattern变量中不存在。查看此软件包中查看
urls.py
文件(请参阅 https://github.com/summernote/django-summernote/blob/main/main/django_summernote/urls.py )我们可以看到,仅在'disable_atecthachment
'
配置的键值为false
。检查您的
settings.py
文件,并查找summernote_config
变量。在那里,您应该看到'Disable_attachment'
键。确保其值设置为false
(请参阅 https:// https:/// github.com/summernote/django-summernote#options )。否则,将不会注册Django试图接触的urlpattern
您将获得发布的错误。附带说明,请注意
urls.py
文件和其中包含的模式,因为您在两个不同的端点中包含了相同的模式:如果包含的模式为同样的命名。删除这两种模式之一将完成这项工作,只需在其他文件中考虑一下即可!
It seems that the pattern with name 'django_summernote-upload_attachment' is not present in your urlpatterns variable. Looking at the
urls.py
file from this package (see https://github.com/summernote/django-summernote/blob/main/django_summernote/urls.py) we can see that the corresponding pattern is added only if the'disable_attachment'
key value for the config isFalse
.Check your
settings.py
file and look for theSUMMERNOTE_CONFIG
variable. There you should see the'disable_attachment'
key. Make sure that its value is set toFalse
(see https://github.com/summernote/django-summernote#options). Otherwise, theurlpattern
that Django is trying to reach won't be registered and you will get the error that you posted.As a side note, take care with the
urls.py
file and the patterns included there because you are including the same set of patterns in two different endpoints:This can cause redirection problems if the patterns included have the same naming. Removing one of these two patterns will do the job, just take it into account across your other files!