反向' django_summernote-upload_attachment'未找到。 ' django_summernote-upload_attachment'不是有效的视图功能或模式名称

发布于 2025-01-24 08:59:24 字数 2453 浏览 4 评论 0原文

当我尝试添加帖子时,我会一直遇到此错误。 ,

“找不到'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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃→可爱长大的 2025-01-31 08:59:25

这就是我的URL的外观,并且运行良好,但是在我遇到相同的错误之前,我通过添加这两条路径 Summernote 编辑来修复它。

urlpatterns = [
    path('', RedirectView.as_view(url='admin/login/', permanent=False), name='/'),
    path('admin/', admin.site.urls),
    path('summernote/', include('django_summernote.urls')),
    path('editor/', include('django_summernote.urls')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

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

urlpatterns = [
    path('', RedirectView.as_view(url='admin/login/', permanent=False), name='/'),
    path('admin/', admin.site.urls),
    path('summernote/', include('django_summernote.urls')),
    path('editor/', include('django_summernote.urls')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
够运 2025-01-31 08:59:25

似乎名称的模式'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文件和其中包含的模式,因为您在两个不同的端点中包含了相同的模式:

 path('summernote/', include('django_summernote.urls')), # using include('django_summernote.urls')
 path('editor/', include('django_summernote.urls')) # using include('django_summernote.urls') once again

如果包含的模式为同样的命名。删除这两种模式之一将完成这项工作,只需在其他文件中考虑一下即可!

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 is False.

Check your settings.py file and look for the SUMMERNOTE_CONFIG variable. There you should see the 'disable_attachment' key. Make sure that its value is set to False (see https://github.com/summernote/django-summernote#options). Otherwise, the urlpattern 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:

 path('summernote/', include('django_summernote.urls')), # using include('django_summernote.urls')
 path('editor/', include('django_summernote.urls')) # using include('django_summernote.urls') once again

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文