部署到Pythonywhere后,获取NoReverseMatch错误
我正在尝试djangoGirls教程,在完成ExtendYour应用程序之后,我的站点在本地和远程运行良好。但是当我拉到PythonAnyWhere并尝试访问该站点时,我得到了错误NoReverseMatch,如下图所示: 所以我想知道是否有人知道我能做些什么来解决这个问题,因为我尝试了,但做不到。我不知道该怎么做 我的所有代码与本教程类似,如下所示: URL.py:部署到Pythonywhere后,获取NoReverseMatch错误,python,django,Python,Django,我正在尝试djangoGirls教程,在完成ExtendYour应用程序之后,我的站点在本地和远程运行良好。但是当我拉到PythonAnyWhere并尝试访问该站点时,我得到了错误NoReverseMatch,如下图所示: 所以我想知道是否有人知道我能做些什么来解决这个问题,因为我尝试了,但做不到。我不知道该怎么做 我的所有代码与本教程类似,如下所示: URL.py: from django.conf.urls import url from . import views urlpat
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.post_list),
url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail),
]
models.py:
from django.db import models
from django.utils import timezone
class Post(models.Model):
author = models.ForeignKey('auth.User')
title = models.CharField(max_length = 200)
text = models.TextField()
created_date = models.DateTimeField(default = timezone.now)
published_date = models.DateTimeField(blank = True, null = True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.title
base.html
{% load staticfiles %}
<html>
<head>
<title>Django Girls 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>
{%load staticfiles%}
Django女孩博客
{%block content%}
{%endblock%}
post_lists.html:
{% extends 'blog/base.html' %}
{% block content %}
{% for post in posts %}
<div class="post">
<div class="date">
{{ post.published_date }}
</div>
<h1><a href="{% url 'blog.view.post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
<p>{{ post.text|linebreaksbr }}</p>
</div>
{% endfor %}
{% endblock content %}
{%extends'blog/base.html%}
{%block content%}
{posts%%中的post为%s}
{{post.published_date}
{{post.text | linebreaksbr}}
{%endfor%}
{%endblock内容%}
post_detail.html:
{% extends 'blog/base.html' %}
{% block content %}
<div class="post">
{% if post.published_date %}
<div class="date">
{{ post.published_date }}
</div>
{% endif %}
<h1>{{ post.title }}</h1>
<p>{{ post.text|linebreaksbr }}</p>
</div>
{% endblock %}
{%extends'blog/base.html%}
{%block content%}
{%if post.published_date%}
{{post.published_date}
{%endif%}
{{post.title}}
{{post.text | linebreaksbr}}
{%endblock%}
github上的项目链接是github.com/lucasdaquina/my-first-blog
很抱歉,没有在上面添加链接,我还不能添加多个链接
如果我需要一些其他必要的信息来帮助我,现在就告诉我。
感谢大家的帮助和关注。当您按照操作时,首先会出现NoReverseMatch
错误。然后,它将向您展示如何修复它
首先,url标记应该只包含'post\u detail'
,而不是像您所拥有的那样包含'blog.view.post\u detail'
{% url 'post_detail' pk=post.pk %}"
然后,本教程让您在URL模式中添加一个名称以修复错误:
url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail, name="post_detail"),
url(r'^post/(?P[0-9]+)/$),views.post\u detail,name=“post\u detail”),
当您按照操作时,首先应该会出现NoReverseMatch
错误。然后,它将向您展示如何修复它
首先,url标记应该只包含'post\u detail'
,而不是像您所拥有的那样包含'blog.view.post\u detail'
{% url 'post_detail' pk=post.pk %}"
然后,本教程让您在URL模式中添加一个名称以修复错误:
url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail, name="post_detail"),
url(r'^post/(?P[0-9]+)/$),views.post\u detail,name=“post\u detail”),
是否尝试重新加载服务器?我认为它可以缓存python文件,但不能缓存模板。也许可以尝试重新加载服务器?我认为它可以缓存python文件,但不能缓存模板。