Redirect to admin for login

redirect wordpress back to referring page after login
peter's login redirect
redirect after login wordpress
wordpress redirect after login based on role
peter's login redirect not working
wordpress login redirect plugin
after login redirect to requested page in wordpress
redirect after login php

I have a view defined for a url 'site/main/'. I would like to be able to have (unauthenticated) users redirected to the default '/admin/' page for login, then redirected to the '/main/' page after successful login. I followed the django documentation, but I must be missing something as I am unable to get this to work. My view looks like:

def main(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('admin/?next=%s' % request.path)
    else:

I get an error:

Page not found (404) Request Method: GET Request URL:http://sitename:8080/main/admin/?next=/main/

Any help is greatly appreciated !

You're missing an initial / in the URL: /admin/?next=...

However this still won't work, as the admin URL doesn't know anything about the next parameter. That's only for the actual login views. With your code, the user will be logged into the admin but will not be redirected back to your page.

You should build a login template and wire it up to the built-in login views. Then instead of checking is_authenticated in the view, you should just use the login_required decorator.

@login_required
def main(request):
   ...

How to Redirect Users after Successful Login in WordPress, profile section in the WordPress admin area. In this guide, we'll show you how to easily Duration: 7:09 Posted: Dec 18, 2019 If you want to redirect to admin for login for specific view, and then to redirect back to the view url after successful login you only need to do two things: Add LOGIN_URL to settings.py inside your django project module: LOGIN_URL = '/admin/login/' Add @login_required as decorator to your view function inside views.py:

Your request.path shouldn't be /main/. Try it without the first.

Admin login redirect problem, After passing login form users were redirected to initial requested page. Now everything based on Django default login actions redirects to admin. Looks like� Then we can customize this using the WordPress login redirect functions. We see how to use this for both frontend and wp-admin logins. By the end of this read, you get a new understanding of the WordPress redirect after login functions. Let’s get started! The default WordPress login redirect behavior

  1. urls.py:

                        url('^', include('django.contrib.auth.urls')),
    
  2. registration/login.html:

  <h3>Login foo</h3>
    <form method="post" action="">
    {% csrf_token %}
    {{form.as_p}}
    <input type="submit" value="Login">
    </form>

Admin Page Redirect, /** * Redirect admin pages. * * Redirect specific admin page to another specific admin page. * * @return void * @author Michael Ecklund * */ function� Sometimes you may keep locked away from your WordPress admin panel and sometimes you may face WordPress login redirect problem. There are many problems to solve for a perfect website. In this article, I am going to tell you how to solve login page refreshing problem. There are many bloggers whose WordPress wp-admin redirects to homepage.

If you want to redirect to admin for login for specific view, and then to redirect back to the view url after successful login you only need to do two things:

  1. Add LOGIN_URL to settings.py inside your django project module:
...
LOGIN_URL = '/admin/login/'
  1. Add @login_required as decorator to your view function inside views.py:
from django.contrib.auth.decorators import login_required
...
@login_required
def main(request):

Once you set LOGIN_URL = '/admin/login/' you can use @login_required on whatever view in entire django project and it will redirect to admin for login and after successful login will redirect back to the view url.

Also now you don't need to use is_authenticated any more inside of a view as Daniel Roseman already said.

The good thing is that now you also don't need to build a login template and wire it up to the built-in login views.

What is also good with this approach is the you have flexibility to easily add or remove this kind of authentication to whatever view you want.

Redirect Admin User in Dashboard, You should not use Userlevels. Userlevels have been replaced in WP 2.0 and have been officially deprecated since 3.0 add_filter( 'login_redirect'� Incorrect WordPress URL settings and failure to set login cookies are the most common reasons causing the login page redirect and refresh issue. Normally, when you login, WordPress validates your username and password and then sets a login cookie in your browser. After that, it redirects you to the WordPress admin area.

Different login redirect for admins, [This thread is closed.] I have deactivated the WP core login/registration pages in the User Registration settings (to force registrations through… If you're a super administrator and you sign in to admin.google.com with your full administrator address (name@example.com) and password, you're redirected to the Admin console. Google does not redirect you to the SSO server.

wp-admin redirects to wp-login wordpresswp-admin&reauth=1 , [This thread is closed.] Hi there! My website redirects to a completely different URL: https://mnskp.nl/wp-login.php?redirect_to=https%3A%2F%2Fmnskp.… We would like to show you a description here but the site won’t allow us.

How to redirect users after login in drupal?, Then, after making sure the core module Trigger is enabled at /admin/modules ( or using Drush), assign the URL redirect action you just defined to the "After a user� >The New Standard for Internet Fax and Cloud-based Fax Services

Comments
  • Thanks to @daniel-roseman for the answer. One small change was required when following the directions. <a href="stackoverflow.com/questions/4578685/…>. I encountered the same error as <a href="stackoverflow.com/questions/4578685/…" title="example">NoReverseMatch while rendering</a>, which has the solution.
  • To catch up with your issue, it would be easier if you also state the imports. Here: from django.http import HttpResponseRedirect
  • exactly what I experienced after adding the '/' to the '/admin/'. The part where you lose me is "You should build a login template and wire it up to the built-in login views." I'm not quite sure how to wire it up... and building the login template... I'm VERY new to django (if that isn't clear already :-) )
  • It's fully explained here: docs.djangoproject.com/en/1.4/topics/auth/…
  • Thanks ! One small change was required when following the directions. I encountered the same error as NoReverseMatch while rendering , which has the solution.
  • thanks !.... changing HttpResponseRedirect('admin/?next=%s) to: HttpResponseRedirect('/admin/?next=%s) does actually redirect the user the the login screen (which is great !).... but the "next=main" doesn't seem to be respected...once logged in the user remains on the admin page... any ideas ?