NoReverseMatch в / notes / Reverse для 'note_detail' с аргументами '(' ',)' не найден.Попробован 1 шаблон (ов): ['notes \ / (? P [- \ w] +) / $'] Метод запроса: GET URL запроса: http://127.0.0.1:8000/notes/ Версия Django: 2.0.3 Тип исключения: NoReverseMatch ExceptionЗначение:
Обратное значение для 'note_detail' с аргументами '(' ',)' не найдено.Испытано 1 шаблонов: ['notes \ / (? P [- \ w] +) / $'] Расположение исключения: C: \ Users \ auwwa \ Desktop \ notes \ lib \ site-packages \ django \ urls \resolvers.py в _reverse_with_prefix, строка 632 Исполняемый файл Python: C: \ Users \ auwwa \ Desktop \ notes \ Scripts \ python.exe Версия Python: 3.6.4 Путь к Python:
['C: \ Users \ auwwa \ Desktop \notes \ src \ notes ',' C: \ Users \ auwwa \ Desktop \ notes \ Scripts \ python36.zip ',' C: \ Users \ auwwa \ Desktop \ notes \ DLLs ',' C: \ Users \ auwwa \ Desktop\ notes \ lib ',' C: \ Users \ auwwa \ Desktop \ notes \ Scripts ',' C: \ Users \ auwwa \ AppData \ Local \ Programs \ Python \ Python36 \ Lib ',' C: \ Users \ auwwa \AppData \ Local \ Programs \ Python \ Python36 \ DLLs ',' C: \ Users \ auwwa \ Desktop \ notes ',' C: \ Users \ auwwa \ Desktop \ notes \ lib \ site-packages '] Время сервера: ср.,24 октября 2018 21:18:57 + 0000
У меня возникла проблема Реверс для 'note_detail' с аргументами '(' ',)' не найден.Попробован 1 шаблон (ов): ['notes \ / (? P [- \ w] +) / $']
это просмотров:
from django.shortcuts import render
from .models import Note
from django.contrib.auth.models import User
from .forms import NoteForm
# Create your views here.
def all_notes(request):
all_notes = Note.objects.all()
context = {
'all_notes':all_notes,
}
return render(request, 'all_notes.html',context)
def detail(request, slug):
note = Note.objects.get(slug=slug)
context = {
'note':note
}
return render(request, 'note_details.html', context)
def note_add(request):
if request.method == 'POST':
form = NoteForm(request.POST)
if form.is_valid():
new_form = form.save(commit=False)
new_form.user = request.user
new_form.save()
else:
form = NoteForm()
context={
'form':form
}
return render(request, 'add.html',context)
и url nots_app:
from django.conf.urls import url
from . import views
app_name = "notes_app"
urlpatterns = [
url(r'^$', views.all_notes, name='all_notes'),
url(r'^(?P<slug>[-\w]+)/$', views.detail , name='note_detail'),
url(r'^Add$', views.note_add, name='add_note'),
]
forms.py ::
from django import forms
from .models import Note
class NoteForm(forms.ModelForm):
class Meta:
model = Note
fields = ['title', 'content', 'tags']
all-notes.html ::
<h1>Welcome in my notes</h1>
<h3>All The Available Notes</h3>
<a href="{% url 'notes:add_note' %}">Add New Notes</a>
<br>
<hr>
{% for note in all_notes %}
<a href="{% url 'notes:note_detail' note.slug %}">{{note}}</a>
<br>
{% endfor %}
notes_detail.html ::
<h1>welcome</h1>
{{note}}<br>
{{note.content}}<br>
{{note.created}}<br>
{{note.tags}} <br>
models.py :::
from django.db import models
from django.contrib.auth.models import User
import datetime
from django.utils.text import slugify
# Create your models here.
class Note(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=50)
slug = models.SlugField(null=True,blank=True)
content = models.TextField(blank=True)
created = models.DateTimeField(blank=True, default=datetime.datetime.now)
active = models.BooleanField(default=True)
tags = models.CharField(blank=True, max_length=100)
def save(self, *args, **kwargs ):
if not self.slug:
self.slug = slugify(self.title)
super(Note, self).save(*args, **kwargs )
def __str__(self):
return self.title