Я разработал свой блог, следуя https://tutorial.djangogirls.org/en
.Веб-сайт работает на локальном хосте, но показывает ошибку NoReverse Match at /
в pythonanywhere.com
Эта ошибка отображается, когда представление не указано.однако я дал фрагменты кода для отображения просмотров.
1) мой views.py
from django.utils import timezone
from .models import Post
# Create your views here.
def post_list(request):
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
return render(request, 'blog/post_list.html', {'posts': posts})
def post_detail(request, pk):
post = get_object_or_404(Post, pk=pk)
return render(request, 'blog/post_detail.html', {'post': post})
2) post_detail.html
{% block content %}
<div class="post">
{% if post.published_date %}
<div class="date">
{{ post.published_date }}
</div>
{% endif %}
<h2>{{ post.title }}</h2>
<p>{{ post.text|linebreaksbr }}</p>
</div>
{% endblock %}
3) post_list.html
{% block content %}
{% for post in posts %}
<div class="post">
<div class="date">
<p>published: {{ post.published_date }}</p>
</div>
<h2><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h2>
<p>{{ post.text|linebreaksbr }}</p>
</div>
{% endfor %}
{% endblock %}
4) и base.html
<html>
<head>
<title>Krishna's blog</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
</head>
<body>
<div class="page-header">
<h1><a href="/">Django Girls Blog</a></h1>
</div>
<div class="content container">
<div class="row">
<div class="col-md-8">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</body>
</html>
1) отображаемая ошибка:
Reverse for 'post_detail' not found. 'post_detail' is not a valid view function or pattern name.
Request Method: GET
Request URL: http://bhawanabadlani.pythonanywhere.com/
Django Version: 2.0.13
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'post_detail' not found. 'post_detail' is not a valid view function or pattern name.
Exception Location: /home/bhawanabadlani/.virtualenvs/bhawanabadlani.pythonanywhere.com/lib/python3.5/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 634
Python Executable: /usr/local/bin/uwsgi
Python Version: 3.5.6
Python Path:
['/home/bhawanabadlani/bhawanabadlani.pythonanywhere.com',
'/var/www',
'.',
'',
'/var/www',
'/home/bhawanabadlani/.virtualenvs/bhawanabadlani.pythonanywhere.com/lib/python35.zip',
'/home/bhawanabadlani/.virtualenvs/bhawanabadlani.pythonanywhere.com/lib/python3.5',
'/home/bhawanabadlani/.virtualenvs/bhawanabadlani.pythonanywhere.com/lib/python3.5/plat-linux',
'/home/bhawanabadlani/.virtualenvs/bhawanabadlani.pythonanywhere.com/lib/python3.5/lib-dynload',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-linux',
'/home/bhawanabadlani/.virtualenvs/bhawanabadlani.pythonanywhere.com/lib/python3.5/site-packages']
Server time: Tue, 24 Sep 2019 13:37:10 +0530
Error during template rendering
In template /home/bhawanabadlani/bhawanabadlani.pythonanywhere.com/blog/template/blog/base.html, error at line 6
Reverse for 'post_detail' not found. 'post_detail' is not a valid view function or pattern name.
1 {% load static %}
2 <html>
3 <head>
4 <title>Krishna's blog</title>
5 <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
6 <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
7 <link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
8 <link rel="stylesheet" href="{% static 'css/blog.css' %}">
9 </head>
10 <body>
11 <div class="page-header">
12 <h1><a href="/">Django Girls Blog</a></h1>
13 </div>
14 <div class="content container">
15 <div class="row">
16 <div class="col-md-8">