Python Django-NoReverseMatch at/Profile/user

Python Django-NoReverseMatch at/Profile/user,python,django,slug,Python,Django,Slug,我的问题是,单击主页上的一个链接后,我遇到了一个NoReverseMatch错误。问题指向一个我拒绝删除的文本文件 这是导致问题的代码 <a href="{% url 'edit_Profile' slug=Profile.slug %}">Edit me!</> url.py from django.conf.urls import url, include from django.contrib import admin from django.views.gene

我的问题是,单击主页上的一个链接后,我遇到了一个NoReverseMatch错误。问题指向一个我拒绝删除的文本文件

这是导致问题的代码

<a href="{% url 'edit_Profile' slug=Profile.slug %}">Edit me!</>
url.py

from django.conf.urls import url, include
from django.contrib import admin
from django.views.generic import TemplateView

from webapp import views


from django.conf.urls import url, include
from django.contrib import admin
from django.views.generic import TemplateView

from webapp import views


urlpatterns = [
    url(r'^$', views.index, name='home'),
    url(r'^about/$',
        TemplateView.as_view(template_name='about.html'), name='about'),
    url(r'^contact/$',
        TemplateView.as_view(template_name='contact.html'), name='contact'),
    url(r'^Profiles/(?P<slug>[-\w]+)/$', views.Profile_detail, 
        name='Profile_detail'),
    url(r'^things/(?P<slug>[-\w]+)/edit/$', 
        views.edit_Profile,
        name='edit_Profile'),
]
profile_detail.html

{% extends 'base.html' %}
{% block title %}
     {{ Profile.name }} - {{ block.super }}
{% endblock title %}

{% block content %}
    <h1>{{ Profile.name }}</h1>
    <p>{{ Profile.description }}</p>
    <a href="{% url 'edit_Profile' slug=Profile.slug %}">Edit me!</>
    {% endblock content %}
{%extends'base.html%}
{%block title%}
{{Profile.name}}-{{block.super}
{%endblock title%}
{%block content%}
{{Profile.name}
{{Profile.description}}

编辑我! {%endblock内容%}
在模板中:

<a href={% url 'about_me' %}>about me</a>

url templatetag中的第一个参数与url.py中的名称匹配,而不是与视图函数的名称匹配。 另一件事是您没有指向edit_Profile函数的条目

要实现这一点,您需要添加一个URL模式,该模式指向URL.py中名为“edit_Profile”的函数,例如:

url(r'^Profiles/(?P<slug>[-\w]+)/edit$', views.edit_Profile, 
    name='edit_Profile')
url(r'^Profiles/(?P[-\w]+)/edit$”,views.edit\u Profile,
name='edit_Profile')

推荐阅读:

我看不到您的url
edit\u Profile
是在
urlpatterns
中配置的,您错过了
url(r'^Profile/(?p[-\w]+)/edit/$,views.edit\u Profile,name='edit\u Profile'),
好眼!但不幸的是,模板问题仍然存在。你能详细介绍一下模板吗?如果你指的是链接的话)。您提到的错误是由于缺少名为“edit_Profile”的urlpattern造成的。
url(r'^Profiles/(?P<slug>[-\w]+)/$', views.Profile_detail, 
        name='Profile_detail')
(r'^about_me/', about_me_view, name='about_me')
<a href={% url 'about_me' %}>about me</a>
url(r'^Profiles/(?P<slug>[-\w]+)/edit$', views.edit_Profile, 
    name='edit_Profile')