尝试在Django中测试re_路径正则表达式

2024-10-02 16:26:31 发布

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

我正在尝试为re_pathurl编写一个测试,但我无法理解它。下面是到目前为止我的代码。请原谅当天的批评和评论。我不知道如何逃脱这个不到的符号

urls.py文件:

from django.urls import path, re_path
from . import views
urlpatterns = [
    re_path(r'trophy/(?P<userid>\w+)/(?P<comment_of_the_day>\w+)/$', views.commentoftheday, name='commentoftheday'),
]

tests.py文件:

from django.test import TestCase, Client
from django.urls import reverse

class helpme(TestCase):
    def test1(self):
        response = self.client.get(reverse("commentoftheday"), kwargs={'userid':'bleh'})
        response.status_code

Tags: 文件pathdjangofrompyimportselfre