Django:“社论”不是注册名称P

2024-09-27 18:01:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到的错误是'editorial' is not a registered namespace

我的博客的Github页面:

https://github.com/OmarGonD/el-comercio-editoriales

我发现了类似的问题:

Django - is not a registered namespace

但我目前正在使用它的解决方案(在项目url文件中使用名称空间),但仍然得到了错误

项目URL.py:

"""el_comercio_app URL Configuration"""

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
     path("", include("editorial.urls", namespace='editorial')),
]

编辑URL.py:

from django.urls import path
from editorial import views
from django.contrib import admin

app_name = 'editorial'

urlpatterns = [
    path('admin', admin.site.urls),
    path("", views.today_editorial, name="today_editorial")
]

运行测试时发生错误:

coverage run manage.py test editorial -v 2

# models test
class EditorialTest(TestCase):

    def create_editorial(self, title="only a test", body="yes, this is only a test"):
        return Editorial.objects.create(title=title, body=body,
               url="https://www.google.com", image = "https://img.elcomercio.pe/files/article_content_ec_fotos/uploads/2019/06/19/5d0ae893b3287.jpeg",
               date=timezone.now())

    def test_today_editorial_view(self):
        url = reverse("editorial:today_editorial")
        resp = self.client.get(url)

        self.assertEqual(resp.status_code, 200)   

Tags: pathdjangofromhttpstestimportselfurl

热门问题