Regex django url正则表达式不';不匹配

Regex django url正则表达式不';不匹配,regex,django,django-urls,Regex,Django,Django Urls,不确定这与URL.py中的任何URL不匹配的原因。我用正则表达式检查器检查过,应该是正确的 URL.py: url(r'^toggle_fave/\?post_id=(?P<post_id>\d+)$', 'core.views.toggle_fave', name="toggle_fave"), url(r'^toggle\u fave/\?post\u id=(?P\d+)$,'core.views.toggle\u fave',name=“toggle\u fave”),

不确定这与URL.py中的任何URL不匹配的原因。我用正则表达式检查器检查过,应该是正确的

URL.py:

url(r'^toggle_fave/\?post_id=(?P<post_id>\d+)$', 'core.views.toggle_fave', name="toggle_fave"),
url(r'^toggle\u fave/\?post\u id=(?P\d+)$,'core.views.toggle\u fave',name=“toggle\u fave”),
示例url:

http://localhost:8000/toggle_fave/?post_id=7

使用简单的regex Checked进行检查。似乎是对的。有什么想法吗


谢谢

urlconf未用于匹配请求。获取url的参数。您可以在视图中执行此操作

您希望您的URL如下所示:

 http://localhost:8000/toggle_fave/7/
并使用以下方法进行匹配:

url(r'^toggle_fave/(?P<post_id>\d+)/$', 'core.views.toggle_fave', name="toggle_fave"),

和您的URL.py:

url(r'^toggle_fave/$', 'core.views.toggle_fave', name="toggle_fave"),
和views.py:

def toggle_fave(request):
    post_id = request.GET.get('post_id', '')
    if post_id:
        post = get_object_or_404(Post, pk=post_id)
    ...

urlconf未用于匹配请求。获取url的参数。您可以在视图中执行此操作

您希望您的URL如下所示:

 http://localhost:8000/toggle_fave/7/
并使用以下方法进行匹配:

url(r'^toggle_fave/(?P<post_id>\d+)/$', 'core.views.toggle_fave', name="toggle_fave"),

和您的URL.py:

url(r'^toggle_fave/$', 'core.views.toggle_fave', name="toggle_fave"),
和views.py:

def toggle_fave(request):
    post_id = request.GET.get('post_id', '')
    if post_id:
        post = get_object_or_404(Post, pk=post_id)
    ...

好的,我明白了,谢谢。虽然我认为urls.py中的regex部分有误导性。好的,我理解,谢谢。尽管我认为urls.py中的regex部分有误导性。