首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django Resolver404错误

Django Resolver404错误
EN

Stack Overflow用户
提问于 2017-11-06 11:17:08
回答 2查看 1.9K关注 0票数 0

在运行python manage.py测试时出现此错误,请帮助我解决此问题

代码语言:javascript
复制
ERROR: test_update_status_table_using_message_table_func (update_status.tests.Up
date_Status_Test)

Traceback (most recent call last):
  File "C:\Users\USER\syuvira\update_status\tests.py", line 67, in test_update_s
tatus_table_using_message_table_func
    found = resolve('/update-status/show_post')
  File "C:\Users\USER\env\lib\site-packages\django\urls\base.py", line 27, in re
solve
    return get_resolver(urlconf).resolve(path)
  File "C:\Users\USER\env\lib\site-packages\django\urls\resolvers.py", line 392,
 in resolve
    raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<RegexURLResolver <RegexURLPatte
rn list> (admin:admin) ^admin/>], [<RegexURLResolver <module 'profile_page.urls'
 from 'C:\\Users\\USER\\syuvira\\profile_page\\urls.py'> (None:profile-page) ^pr
ofile-page/>], [<RegexURLResolver <module 'Add_Friend.urls' from 'C:\\Users\\USE
R\\syuvira\\Add_Friend\\urls.py'> (None:Add-Friend) ^Add-Friend/>], [<RegexURLRe
solver <module 'dashboard.urls' from 'C:\\Users\\USER\\syuvira\\dashboard\\urls.
py'> (None:dashboard) ^dashboard/>], [<RegexURLResolver <module 'welcome_page.ur
ls' from 'C:\\Users\\USER\\syuvira\\welcome_page\\urls.py'> (None:welcome-page)
^welcome-page/>], [<RegexURLPattern index ^$>]], 'path': 'update-status/show_pos
t'}

这是我的tests.py

代码语言:javascript
复制
def test_update_status_using_index_func(self):

    found = resolve('/update-status/')
    self.assertEqual(found.func, index)
EN

回答 2

Stack Overflow用户

发布于 2017-11-06 11:23:37

在您的测试代码中触发的Handle the exception resolve函数。

如果URL不能解析,该函数将引发Resolver404异常(Http404的子类)。

代码语言:javascript
复制
def test_update_status_using_index_func(self):
   try:
       found = resolve('/update-status/')
       self.assertEqual(found.func, index)
   except Resolver404:
       self.fail("Couldn't not resolve URL')
票数 0
EN

Stack Overflow用户

发布于 2020-04-09 01:49:46

另一种测试方法是:

代码语言:javascript
复制
from django.test import Client, TestCase
from django.urls import resolve, Resolver404

from myproject import settings

class TestError404(TestCase):
    def setUp(self):
        self.client = Client()
        self.debug = settings.DEBUG
        settings.DEBUG = False

    def tearDown(self):
        settings.DEBUG = self.debug

    def test_404(self):
        with self.assertRaises(Resolver404):
            resolve('/foo/')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47129236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档