2017-02-28 6 views
0

私のホームページのリンクの1つをクリックすると、NoReverseMatchエラーが表示されます。問題は、削除を拒否するテキストファイルを指しています。Django - NoReverseMatch at/Profile/user

ここHERESに私のコード

views.py

from django.shortcuts import render, redirect 
from django.views.generic.base import TemplateView 
from webapp.models import Profile 
from webapp.forms import ProfileForm 

def index(request): 
    Profiles = Profile.objects.all() 
    return render(request, 'index.html', { 
    'Profiles': Profiles, 
}) 

def Profile_detail(request, slug): 

    Profiles = Profile.objects.get(slug=slug) 
    return render(request, 'Profiles/Profile_detail.html', { 
    'Profile': Profile, 
}) 



def edit_Profile(request, slug): 

    Profile = Profile.objects.get(slug=slug) 
    form_class = ProfileForm 

    if request.method == 'POST': 

     form = form_class(data=request.POST, instance=Profile) 
     if form.is_valid(): 

      form.save() 
      return redirect('Profile_detail', slug=Profile.slug) 

    else: 
     form = form_class(instance=Profile) 

    # and render the template 
    return render(request, 'Profiles/edit_Profile.html', { 
     'Profile': Profile, 
     'form': form, 
    }) 

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'), 
] 

forms.py

0を問題

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

を引き起こしているコードです

from django.forms import ModelForm 

from webapp.models import Profile 

class ProfileForm(ModelForm): 
    class Meta: 
     model = Profile 
     fields = ('name', 'description',) 

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 %} 
+1

私はないんだけどurl(r '^ profile /(?P [ - \ w] +)/ edit/$'、views.edit_Profile、name = 'edit_Profile'が見つかりませんでしたあなたのURLを見て 'edit_Profile'が' urlpatterns'で設定されています。 )、 ' –

+0

いいね!残念ながらテンプレートの問題は残っています。 – aleexownz

答えて

0
url(r'^Profiles/(?P<slug>[-\w]+)/$', views.Profile_detail, 
     name='Profile_detail') 

名は、テンプレート内edit_Profile以外Profile_detailです。

という名前のURLをたとえば、あなたはurl.pyで実行する必要があります。

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

のURL templatetagの最初のパラメータがurls.py中の名前と照合されます:テンプレートで

(r'^about_me/', about_me_view, name='about_me') 

をビュー関数の名前に対してではありません。 もう一つは、edit_Profile関数を指すエントリがないことです。

例えばあなたが名「edit_Profile」でurls.pyに関数にURLPATTERNポインティングを追加する必要があり、この作品を作るために:

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

推奨読書:https://docs.djangoproject.com/en/1.10/topics/http/urls/

+0

テンプレートについてもっと詳しく教えてください。 – aleexownz

+0

リンクEdit me! it should work fine if there's no other problems and if you fix the closing tag (replace withを意味する場合は)。あなたが言及したエラーは、 'edit_Profile'という名前のurlパターンがないことが原因です。 –