How to redirect to 'http://127.0.0.1:8000/profile/' instead of 'http://127.0.0.1:8000/accounts/login/?next=/profile/'

how to redirect a url to another url
how to redirect a url to another url in html
how to do a 301 redirect
javascript redirect
url redirect service
how to redirect a domain
website redirect message examples
redirect checker

I'm trying to edit user profiles. The user edits a form on profile.html and when they submit it, they should be redirected back to profile.html (the same page). Even though I changed my LOGIN_REDIRECT_URL, I'm still redirecting to accounts/login (the default).

views.py

@login_required
def profile(request):
    user = request.user

    if request.method == "POST":
        signupform = SignUpForm(data=request.POST, instance=request.user)
        if signupform.is_valid():
              signupform.save()
              return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
    return render(request, 'profile.html', "context stuff here")

settings.py

LOGIN_REDIRECT_URL = '/profile'

urls.py

url(r'^profile/$', views.profile, name='profile')

How can I successfully redirect to profile.html?


Try this replacing APPNAME with your app's name (same as the app name you declared in INSTALLED APPS section in settings.py) in the code below

return HttpResponseRedirect(reverse('APPNAME:profile'))

and don't forget to import at the top of your page

from django.urls import reverse

5 Ways to Redirect a Website URL, URL redirection is a forwarding technique that should be used to redirect your visitors to the correct website page. Read more on URL redirects  Redirecting HTTP to HTTPS. 1. Redirect All Web Traffic. If you have existing code in your .htaccess, add the following: RewriteEngine On RewriteCond %{SERVER_PORT} 80 2. Redirect Only a Specific Domain. 3. Redirect Only a Specific Folder.


You use @login_required decorator but you are not logged in. So that it redirects you to the login page. If you login then it redirect to /profile.

HTTP redirect code overview: the redirects guide for SEO, The HTTP redirect code, redirect for short, is a way to forward visitors and search engines from one URL to another. Redirects are used when moving content to  Using a Meta Command 1. Access the code for the page you want to redirect. This is a different method that involves you changing the 2. Open the code for edits. Use “Notepad” or a similar text editor to open the webpage's code file. 3. Amend the code. The Meta code goes after the "head" tag


You can do this,

@login_required
#...
   if signupform.is_valid():
          signupform.save()
          return redirect('profile') # or 'app_name:profile' if you have app_name before your urlpatterns.

Your login_required will redirect you to settings.LOGIN_URL

So in your settings add LOGIN_URL = '/login/'

If the user is logged in the views will work perfectly.

Addition to that, (template level) You can also check authentication in html,

{% if user.is_authenticated %}
#html
{% else %}
show something
{% endif %}

Redirections in HTTP, Log into cPanel using the details your host gave you when you first signed up. Scroll to the Domains section and click Redirects. Choose the type of redirect you​  Redirect http to https in NGINX Steps to edit .htaccess file There are specific instructions in the .htaccess file that informs the server how to behave in particular cases and directly affects your site functionality.


How to Create a URL Redirect, A redirect is a way to send both users and search engines to a different URL from the one they originally requested. The three most commonly used redirects are  The simplest way to redirect to another URL is to use an HTML <meta>tag with the http-equiv parameter set to “refresh”. The "content" attribute sets the delay before the browser redirects the user to the new web page. To redirect immediately, set this parameter to “0” seconds for the "content"attribute.


Redirects, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java  A configured website should be able to redirect and accessible on https. HTTPS Redirection in Nginx Login to the Nginx web server and take a backup of nginx.conf or default.conf file (whatever file you are using for server directive)


How To Redirect to Another Webpage, URL redirection, also called URL forwarding, is a World Wide Web technique for making a web page available under more than one URL address. When a web  This is very useful if we want to redirect a certain page to a new location, change the URL structure of a site, remove the “www.” portion of the URL, or even redirect users to another website entirely (just to name a few).