G
G
gederuzsk2020-07-08 08:00:15
Django
gederuzsk, 2020-07-08 08:00:15

Why don't links work in Django in header?

About rendering in one case everything is OK, in another with a similar template - the links are silent.
This is how I try to redirect to the page after filling out the feedback form on the landing page.
Tell me where to look and where to look?

<header>
      <!-- Fixed navbar -->
      <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
        <a class="navbar-brand" href="/#home">Home</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarCollapse">
          <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
              <a class="nav-link" href="/#home">Главная <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="/#blog">Статьи</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="/#contact">Контакты</a>
            </li>
          </ul>
          <!--
          <form class="form-inline mt-2 mt-md-0">
            <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
            <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
          </form>
          -->
        </div>
      </nav>
  </header>


views.py
def post_list(request):
    posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')[0:3]
    if request.method == 'POST':
        f = FeedbackForm(request.POST)
        if f.is_valid():
            f.save()
            return render(request, 'blog/feedback.html')       #### НЕ РАБТАЕТ
    else:
        f = FeedbackForm()
    return render(request, 'blog/post_list.html', {'posts': posts, 'form': f})


def post_detail(request, pk):   ### ВСЕ ОК
    post = get_object_or_404(Post, pk=pk)
    return render(request, 'blog/article.html', {'post': post})


urls.py
app_name = "blog"

urlpatterns = [
    path('', views.post_list, name='post_list'),
    url(r'^api/article/(?P<pk>[0-9]+)/$', views.post_detail, name='post_detail'),
    url(r'^feedback/$', views.feedback, name='feedback'),

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-07-08
@gederuzsk

gederuzsk after submitting the form, that is, after the POST request, no redirect is done now. It just renders another template. To make a redirect, you need to use the redirect function on the feedback view.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question