我遇到了这个异常:
找不到带有参数'(',)'的'user-posts'。尝试了2个模式:['user /(?P [^ /] +)(?P \。[a-z0-9] + /?)$','user /(?P [^ /] + )$']
我不知道出什么问题
这是我的urls.py
urlpatterns = [
path('', PostListView.as_view(), name='blog-home'),
path('user/<str:username>', UserPostListView.as_view(), name='user-posts')
这是我的家
{% for post in posts %}
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ post.author.image.url }}">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="{% url 'user-posts' post.author.username %}">{{ post.author }}</a>
<small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
</div>
<h2><a class="article-title" href="{% url 'post-detail' post.id %}">{{ post.title }}</a></h2>
<p class="article-content">{{ post.content }}</p>
</div>
</article>
为什么会出现此异常?
答案 0 :(得分:1)
您可能有一个帖子,其中的作者姓名为空。您的网址格式仅匹配非空字符串。