M
M
marselabdullin2020-06-17 20:06:25
Django
marselabdullin, 2020-06-17 20:06:25

How to make an anchor to a part of a django page?

There is a link to contacts (they are on the main page at the bottom) and I need to transfer the user to the specified part of the page by clicking

<li class="menu__item menu__item_footer">
                    <a href="{% url 'main:index' %}" class="menu__link">Контакты</a>
                </li>


views.py:
class ContactView(SuccessMessageMixin, FormView):
    template_name = 'main/index.html'
    form_class = EmailForm
    success_url = 'main/index.html'
    success_message = "Письмо успешно отправлено"

    def form_valid(self, form):
        email = form.cleaned_data['email']
        send_mail('Caparol_Center_Spb',
                  'Теперь вы будете получать лучшие предложения шоу-рума',
                  settings.EMAIL_HOST_USER,
                  [email, ],
                  fail_silently=False,)
        success_message = self.get_success_message(form.cleaned_data)
        if success_message:
            messages.success(self.request, success_message)

        if not Subscriber.objects.filter(email=email).exists():
            Subscriber.objects.create(email=email)
        return redirect(reverse('main:index'))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-06-17
@marselabdullin

django doesn't care, the anchor is to the id in the html code, you just need to add #value_of_this_id to the address

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question