Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django 1.8 NoReverseMatch错误_Python_Django - Fatal编程技术网

Python Django 1.8 NoReverseMatch错误

Python Django 1.8 NoReverseMatch错误,python,django,Python,Django,在尝试访问index.html模板中的帖子时出现此错误: {% if hot_posts %} <ul> {% for post in hot_posts %} {% if post.acceptable %} <li> <h2> <a href="{% url 'post:single_post' post.id %}/">{{post.title}}

在尝试访问index.html模板中的帖子时出现此错误:

{% if hot_posts %}
<ul>
    {% for post in hot_posts %}
        {% if post.acceptable %}
        <li>
            <h2>
                <a href="{% url 'post:single_post' post.id %}/">{{post.title}}</a>
            </h2>
            <a href="{% url 'post:single_post' post.id %}/">
                <img src="{{ post.image.url }}" alt="{{post.title}}"
                class="post-img" />
            </a>
            <p>امتیاز: <span>{{ post.likes }}</span></p>
        </li>
        {% endif %}
    {% endfor %}
</ul>
{% else %}
    <p>No posts are avaialable.</p>
{% endif %}
带参数(5、)和关键字参数的“single_post”则相反 找不到“{}”。尝试了1个模式:['$(?P[0-9]+)/$']

index.html模板:

{% if hot_posts %}
<ul>
    {% for post in hot_posts %}
        {% if post.acceptable %}
        <li>
            <h2>
                <a href="{% url 'post:single_post' post.id %}/">{{post.title}}</a>
            </h2>
            <a href="{% url 'post:single_post' post.id %}/">
                <img src="{{ post.image.url }}" alt="{{post.title}}"
                class="post-img" />
            </a>
            <p>امتیاز: <span>{{ post.likes }}</span></p>
        </li>
        {% endif %}
    {% endfor %}
</ul>
{% else %}
    <p>No posts are avaialable.</p>
{% endif %}
项目URL.py:

from django.conf.urls import include, url
from post.admin import site_admin

urlpatterns = [
    url(r'^modir/', include(site_admin.urls)),
    url(r'^$', include('post.urls', namespace='post')),
]
app url.py:

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.index, name="home_page"),
    url(r'^mosama/(?P<post_id>[0-9]+)/$', views.single_post,
        name="single_post")
]
从django.conf.url导入url
从…起导入视图
URL模式=[
url(r'^$',views.index,name=“主页”),
url(r'^mosama/(?P[0-9]+)/$),views.single_post,
name=“单一职位”)
]

从包含post URL的正则表达式中删除
$

url(r'^', include('post.urls', namespace='post')),

从包含post URL的正则表达式中删除
$

url(r'^', include('post.urls', namespace='post')),

从包含post URL的正则表达式中删除
$

url(r'^', include('post.urls', namespace='post')),

从包含post URL的正则表达式中删除
$

url(r'^', include('post.urls', namespace='post')),

我想在主页上显示博客帖子,也可以通过“mosama/post_id/”访问单个帖子。我不想在“/mosama/”下显示帖子,所以我将url.py编辑成现在的样子,我想它正在发挥作用。是的,你更新的url模式看起来更好。另一种方法是将
视图.索引
移动到项目URL中,然后将
post.URL
包含在
^mosama/
下。我希望主页显示博客帖子,也可以通过“mosama/post_id/”访问单个帖子我不想在“/mosama/”下发布帖子,所以我将url.py编辑成现在的样子,我想它正在发挥作用。是的,你更新的url模式看起来更好。另一种方法是将
视图.索引
移动到项目URL中,然后将
post.URL
包含在
^mosama/
下。我希望主页显示博客帖子,也可以通过“mosama/post_id/”访问单个帖子我不想在“/mosama/”下发布帖子,所以我将url.py编辑成现在的样子,我想它正在发挥作用。是的,你更新的url模式看起来更好。另一种方法是将
视图.索引
移动到项目URL中,然后将
post.URL
包含在
^mosama/
下。我希望主页显示博客帖子,也可以通过“mosama/post_id/”访问单个帖子我不想在“/mosama/”下发布帖子,所以我将url.py编辑成现在的样子,我想它正在发挥作用。是的,你更新的url模式看起来更好。另一种方法是将
视图.index
移动到项目URL中,然后将
post.URL
包含在
^mosama/
下。