Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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 为什么我的url在“中”;不匹配任何url“;什么时候?我不知道如何修复它,我做错什么了吗?_Python_Django_Django Urls_Django Class Based Views - Fatal编程技术网

Python 为什么我的url在“中”;不匹配任何url“;什么时候?我不知道如何修复它,我做错什么了吗?

Python 为什么我的url在“中”;不匹配任何url“;什么时候?我不知道如何修复它,我做错什么了吗?,python,django,django-urls,django-class-based-views,Python,Django,Django Urls,Django Class Based Views,我不会撒谎,这对我来说没有任何意义,为什么这试图访问“帖子细节”而不是“创建帖子”,我该如何修复它?先谢谢你 错误: NoReverseMatch at/create/ 找不到参数为“(“”,)”的“发布详细信息”的反向项。尝试了1个模式: ['(?P[-a-zA-Z0-9+)/post/$'] 请求方法:获取 请求URL: Django版本:3.2.2 异常类型:NoReverseMatch 异常值: 找不到参数为“(“”,)”的“发布详细信息”的反向项。尝试了1种模式:['(?P[-a-zA

我不会撒谎,这对我来说没有任何意义,为什么这试图访问“帖子细节”而不是“创建帖子”,我该如何修复它?先谢谢你

错误:

NoReverseMatch at/create/ 找不到参数为“(“”,)”的“发布详细信息”的反向项。尝试了1个模式: ['(?P[-a-zA-Z0-9+)/post/$'] 请求方法:获取 请求URL: Django版本:3.2.2 异常类型:NoReverseMatch 异常值:
找不到参数为“(“”,)”的“发布详细信息”的反向项。尝试了1种模式:['(?P[-a-zA-Z0-9_337;]+)/post/$']

创建后视图:

class PostCreate(CreateView):
    model = Post
    form_class = PostCreateForm
    template_name = 'post/post_create.html'
    context_object_name = 'form'

    def get_success_url(self):
        return reverse('post:home')

    def form_valid(self, form):
        form.instance.author = self.request.user.profile
        return super().form_valid(form)
{% extends 'base.html' %}


{% block content %}
    <div class="container mt-5 mb-5">

        <form action="" class="commenting-form" method="post" enctype="multipart/form-data">
            <div class="row">
                <div class="form-group col-md-12">
                    {% csrf_token %}
                    {{ form.tags }}

                    <div class="form-group col-md-12">
                        <button type="submit" class="btn btn-secondary mt-2">Edit comment</button>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group col-md-12">
                    {% csrf_token %}
                    {{ form.body }}
                    {{ form.picture }}
                    <div class="form-group col-md-12">
                        <button type="submit" class="btn btn-secondary mt-2">Edit comment</button>
                    </div>
                </div>
            </div>
        </form>

        <hr>
        <a class="btn btn-info" href="{% url 'post:post-details' post_slug %}">Back</a>
    </div>

{% endblock content %}
我的网址:

from django.urls import path, include
from . import views

app_name = 'post'

urlpatterns = [
    path('', views.PostList.as_view(), name='home'),
    path('<slug:slug>/post/', views.PostDetails.as_view(), name='post-details'),
    path('search/', views.search, name='search'),
    path('comment-delete/<pk>/', views.CommentDelete.as_view(), name='comment-delete'),
    path('comment-update/<pk>/', views.CommentUpdate.as_view(), name='comment-update'),
    path('tag/<str:name>/', views.PostTagList.as_view(), name='tag-posts'),
    path('create/', views.PostCreate.as_view(), name='create-post')
]
从django.url导入路径,包括
从…起导入视图
应用程序名称='post'
URL模式=[
路径(“”,views.PostList.as_view(),name='home'),
路径('/post/',views.PostDetails.as_view(),name='post-details'),
路径('search/',views.search,name='search'),
路径('comment-delete/',views.CommentDelete.as_view(),name='comment-delete'),
路径('comment-update/',views.CommentUpdate.as_view(),name='comment-update'),
路径('tag/',views.PostTagList.as_view(),name='tag-posts'),
路径('create/',views.PostCreate.as_view(),name='create-post')
]
“我的后期创建”视图中的post_create.html文件:

class PostCreate(CreateView):
    model = Post
    form_class = PostCreateForm
    template_name = 'post/post_create.html'
    context_object_name = 'form'

    def get_success_url(self):
        return reverse('post:home')

    def form_valid(self, form):
        form.instance.author = self.request.user.profile
        return super().form_valid(form)
{% extends 'base.html' %}


{% block content %}
    <div class="container mt-5 mb-5">

        <form action="" class="commenting-form" method="post" enctype="multipart/form-data">
            <div class="row">
                <div class="form-group col-md-12">
                    {% csrf_token %}
                    {{ form.tags }}

                    <div class="form-group col-md-12">
                        <button type="submit" class="btn btn-secondary mt-2">Edit comment</button>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="form-group col-md-12">
                    {% csrf_token %}
                    {{ form.body }}
                    {{ form.picture }}
                    <div class="form-group col-md-12">
                        <button type="submit" class="btn btn-secondary mt-2">Edit comment</button>
                    </div>
                </div>
            </div>
        </form>

        <hr>
        <a class="btn btn-info" href="{% url 'post:post-details' post_slug %}">Back</a>
    </div>

{% endblock content %}
{%extends'base.html%}
{%block content%}
{%csrf_令牌%}
{{form.tags}}
编辑评论
{%csrf_令牌%}
{{form.body}}
{{form.picture}
编辑评论

{%endblock内容%}
我如何将slug值传递给“post details”

    {% extends 'base.html' %}
{% load static %}

{% block content %}

<div class="container">
    <div class="row">
        <!-- Latest Posts -->
        <main class="posts-listing col-lg-8">
            <div class="container">
                <div class="row">

                    {% for post in posts %}
                        <div class="post col-xl-6">
                            <div class="post-thumbnail">
                                <a href="{% url 'post:post-details' post.slug %}">
                                    <img src="{{ post.picture.url }}" alt="..." class="img-fluid post-picture">
                                </a>
                            </div>
                            <div class="post-details">
                                <div class="post-meta d-flex justify-content-between">
                                    <div class="date meta-last">{{ post.created|timesince }}</div>
                                    <div class="category">
                                        {% for tag in post.tags.all %}
                                        <a href="#">{{ tag }} </a>
                                        {% endfor %}
                                    </div>
                                </div>
                                <a href="post.html"></a>
                                <p class="text-muted">{{ post.body }}</p>
                                <div class="post-footer d-flex align-items-center"><a href="#"
                                                                                      class="author d-flex align-items-center flex-wrap">
                                    <div class="avatar"><img src="{{ post.author.avatar.url }}" alt="..." class="img-fluid"></div>
                                    <div class="title"><span>{{ post.author }}</span></div>
                                </a>

                                    <div class="comments meta-last"><i class="icon-comment"></i>{{ post.get_comment_number }}</div>
                                </div>
                            </div>
                        </div>
                    {% endfor %}


                </div>
                <!-- Pagination -->
                

            </div>
        </main>

        {% include 'sidebar.html' with common_tags=common_tags latest_posts=latest_posts %}
    </div>
</div>


{% endblock content %}
{%extends'base.html%}
{%load static%}
{%block content%}
{posts%%中的post为%s}
{{post.created | timesince}}
{post.tags.all%中标记的%s}
{%endfor%}

{{post.body}

{{post.get_comment_number} {%endfor%} {%include'sidebar.html'和common_tags=common_tags latest_posts=latest_posts%} {%endblock内容%}
你如何将
post\u slug
的值传递给html模板?这是你要求的吗?不。
post\u create.html
模板底部有一行:
你如何将post\u slug传递给此模板?哦,天哪,你说得对,我没有传递这个,谢谢,它是固定的