title: How can I disable URL redirect when I have a "next" url? - Django
body: <p>I have created a blog with Django and whenever a user logs in, the URL redirects to the homepage and displays a success message. This is fine, however, whenever a login is required to view a certain page, Django redirects to the login page and attaches "?next=" to the end of the URL to redirect back to the previous page. The problem is that after the user logs in, the "next" URL is not executed and Django redirects to the homepage and displays the success message? Is there a way to disable this redirect whenever there is a "next" URL?</p>
  
  <p>views.py</p>
  
  <pre><code>from django.urls import reverse
  from django.contrib import messages
  from django.shortcuts import render, redirect
  from django.contrib.auth import login
  from django.utils.safestring import mark_safe
  from .forms import UserLoginForm
  
  def login_view(request):
      if request.method == 'POST':
          form = UserLoginForm(data=request.POST)
          if form.is_valid():
              student = form.get_user()
              login(request, user)
              create_url = reverse('post-create')
              messages.success(request, mark_safe(f'You are now logged in. Do you want to &lt;a href="{ create_url }" class="link" title="Create a post"&gt;create a post&lt;/a&gt;?'))
              return redirect('home')
      else:
          form = UserLoginForm()
      return render(request, 'users/login.html', {'form': form, 'title': 'Log in'})
  </code></pre>