Я пытаюсь отправить форму на мой взгляд:
в тренде. html:
{% extends 'djangobin/base.html' %}
{% load static %}
{% load humanize %}
{% block title %}
Trending {{ lang.name }} Snippets - {{ block.super }}
{% endblock %}
{% block main %}
<h5><i class="fas fa-chart-line"></i> Trending {{ lang.name }} Snippets</h5>
<hr>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Date</th>
<th>Hits</th>
<th>Language</th>
<th>User</th>
</tr>
</thead>
<tbody>
{% for snippet in snippets %}
<tr>
<td><i class="fas fa-globe"></i>
<a href="{{ snippet.get_absolute_url }}">{{ snippet.title }}</a>
</td>
<td title="{{ snippet.created_on }}">{{ snippet.created_on|naturaltime }}</td>
<td>{{ snippet.hits }}</td>
<td><a href="{% url 'trending_snippets' snippet.language.slug %}">{{ snippet.language }}</a></td>
{% if not snippet.user.profile.private %}
<td><a href="{{ snippet.user.profile.get_absolute_url }}">{{ snippet.user.username|title }}</a></td>
{% else %}
<td>-</td>
{% endif %}
</tr>
{% empty %}
<tr class="text-center">
<td colspan="4">There are no snippets.</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
в views.py:
from django.shortcuts import HttpResponse, render, redirect, get_object_or_404, reverse
from .forms import SnippetForm
from .models import Language, Snippet
def trending_snippets(request, language_slug=''):
lang = None
snippets = Snippet.objects
if language_slug:
snippets = snippets.filter(language__slug=language_slug)
lang = get_object_or_404(Language, slug=language_slug)
snippets = snippets.all()
return render(request, 'djangobin/trending.html', {'snippets': snippets, 'lang': lang})
в urls.py:
from django.conf.urls import url
from . import views as views
urlpatterns = [
url('^trending/$', views.trending_snippets, name='trending_snippets'),
url('^trending/(?P<language_slug>[\w]+)/$', views.trending_snippets, name='trending_snippets'),
]
Я получил следующую ошибку:
NoReverseMatch в / trending / Reverse для 'trending_snippets' с аргументами '(' c -sharp ',)' не найден. Попробовано 2 рисунков: ['trending / (? P [\ w] +) / $', 'trending / $']
Тип исключения: NoReverseMatch
Ошибка при отображении шаблона
Справочный сайт: overiq.com
Справочный сайт Ссылка: https://overiq.com/django-1-11/creating-trending-snippet-page/
Python версия: 3.8.2
Django версия: 3.0.5
ОС: Windows 8,1 (32 бита)