登录后重定向到登录页面

时间:2021-03-23 03:58:48

标签: python html css django firebase

我目前正在开发一个 Django 网络应用程序,但是我有一个问题:登录后,用户点击任何按钮,例如。主页(已通过 @login_required 装饰器链接到视图)并被注销并重定向回登录页面。我正在使用 Firebase 进行身份验证。

我的views.py:

def postsign(request):
    email=request.POST.get('email')
    passw=request.POST.get('pass')
    try:
        user=auth.sign_in_with_email_and_password(email,passw)
        
    except:
        message="Invalid credentials. Try again."
        return render(request,"login.html", {"msg":message})    
    
    session_id=user['idToken'] 

    request.session['uid']=str(session_id) 
   
    return render(request,"pick.html") 


@login_required(login_url='login')
def pick(request):
   
    return render_to_response('pick.html')

我的pick.html:

{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  
  <title>FYP - Is Your Network Safe?</title>

  <!-- Bootstrap core CSS -->
  <link href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
  <link href="{% static 'vendor/bootstrap/css/loader.css' %}" rel="stylesheet">

  <!-- Custom fonts for this template -->
  <link href="{% static 'vendor/fontawesome-free/css/all.min.css' %}" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">

  <!-- Custom styles for this template -->
  <link href="{% static 'css/grayscale.min.css' %}" rel="stylesheet">
  
  
  <script src="https://api.mapbox.com/mapbox-gl-js/v1.11.1/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v1.11.1/mapbox-gl.css" rel="stylesheet" />

</head>

<body id="page-top">
  
  <!-- Navigation -->
  <nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav">
    <div class="container">
      <a class="navbar-brand js-scroll-trigger" href="#page-top">TestPage</a>
      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
        Menu
        <i class="fas fa-bars"></i>
      </button>
      <div class="collapse navbar-collapse" id="navbarResponsive">
        <ul class="navbar-nav ml-auto">
          <li class="nav-item">
            <a class="nav-link js-scroll-trigger" href="{% url 'pick' %}">Home</a>
          </li>
          <li class="nav-item">
            <a class="nav-link js-scroll-trigger" href="{% url 'logout' %}">Logout</a>
          </li>
        </ul>
      </div>
    </div>
  </nav>
  
 </body>

</html>

我的 login.html:

{% if msg %}
<script>
    alert('{{msg}}');
</script>

{%endif%}

{% if msgg %}
<script>
    alert('{{msgg}}');
</script>

{%endif%}
{% load staticfiles %}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Spectral SC">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="{% static 'css/logincss.css' %}">
    
</head>
<style>
    h1{
        color:#edf1ff;
        text-shadow: 5px 5px 10px black;
    }
.headerone{
    font-family: 'Spectral SC', serif;
    padding: 110px 0;
    text-align: center;
}
body{
    background-color: black;
}
</style>


<body>
    <div class="login-dark">
        
        
     
                <form  action="/post_sign/" method="post">
                    {% csrf_token %}
                    
                    <div class="illustration"><i class="icon ion-ios-locked-outline"></i></div>
                    <div class="form-group">Email: <input type="email" name="email" autocomplete="off" required></div>
                    <div class="form-group">Code: <input type="password" name="pass" autocomplete="off" required></div>
                    <input class="btn btn-primary btn-block" type="submit" value="Sign In"><br>
                    <a href = "mailto:developers@yes.com">Can't Login? Click me, i'll help.</a></form>                
    </div>
</section>

<footer class="bg-black small text-center text-white-50">
   
  </footer>
</body>

</html>

我的 urls.py

from django.contrib import admin
from django.urls import path
from myapp import views as v
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls import include
from myapp.views import postregister, logout_view

urlpatterns = [

    path('pick/', v.pick, name="pick"),
    path('', v.signIn, name="login"),
    path('post_sign/', v.postsign),
    path('accounts/logout/', logout_view, name="logout")
    
]

urlpatterns += staticfiles_urlpatterns()

请注意,点击“主页”按钮后,网址会显示 http://127.0.0.1:8000/?next=/pick/。有什么方法可以解决这个问题,或者有什么关于如何让它工作的建议吗?

1 个答案:

答案 0 :(得分:0)

由于您使用的是 /opt/homebrew/include/QtCore/qglobal.h:667:65: error: expected '>' typename = std::enable_if_t<std::is_arithmetic_v<T> && std::is_arithmetic_v<U> && ^ /opt/homebrew/include/QtCore/qglobal.h:667:65: error: expected ',' or '>' in template-parameter-list /opt/homebrew/include/QtCore/qglobal.h:668:66: error: expected unqualified-id std::is_floating_point_v<T> == std::is_floating_point_v<U> && ^ /opt/homebrew/include/QtCore/qglobal.h:679:35: error: no type named 'Promoted' in namespace 'QTypeTraits::detail' using Promoted = typename detail::Promoted<T, U>::type; ~~~~~~~~~~~~~~~~~^~~~~~~~ /opt/homebrew/include/QtCore/qglobal.h:679:43: error: expected ';' after alias declaration using Promoted = typename detail::Promoted<T, U>::type; ^ /opt/homebrew/include/QtCore/qglobal.h:691:31: error: no template named 'Promoted' in namespace 'QTypeTraits' constexpr inline QTypeTraits::Promoted<T, U> qMin(const T &a, const U &b) ~~~~~~~~~~~~~^ /opt/homebrew/include/QtCore/qglobal.h:693:28: error: no template named 'Promoted' in namespace 'QTypeTraits' using P = QTypeTraits::Promoted<T, U>; ~~~~~~~~~~~~~^ /opt/homebrew/include/QtCore/qglobal.h:694:5: error: unknown type name 'P' P _a = a; ^ /opt/homebrew/include/QtCore/qglobal.h:695:5: error: unknown type name 'P' P _b = b; ^ /opt/homebrew/include/QtCore/qglobal.h:699:31: error: no template named 'Promoted' in namespace 'QTypeTraits' constexpr inline QTypeTraits::Promoted<T, U> qMax(const T &a, const U &b) ~~~~~~~~~~~~~^ /opt/homebrew/include/QtCore/qglobal.h:701:28: error: no template named 'Promoted' in namespace 'QTypeTraits' using P = QTypeTraits::Promoted<T, U>; ~~~~~~~~~~~~~^ /opt/homebrew/include/QtCore/qglobal.h:702:5: error: unknown type name 'P' P _a = a; ^ /opt/homebrew/include/QtCore/qglobal.h:703:5: error: unknown type name 'P' P _b = b; ^ /opt/homebrew/include/QtCore/qglobal.h:707:31: error: no template named 'Promoted' in namespace 'QTypeTraits' constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const U &val, const T &max) ~~~~~~~~~~~~~^ /opt/homebrew/include/QtCore/qglobal.h:710:31: error: no template named 'Promoted' in namespace 'QTypeTraits' constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const T &val, const U &max) ~~~~~~~~~~~~~^ /opt/homebrew/include/QtCore/qglobal.h:713:31: error: no template named 'Promoted' in namespace 'QTypeTraits' constexpr inline QTypeTraits::Promoted<T, U> qBound(const U &min, const T &val, const T &max) fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated. 而不是 HTTP,请检查以下设置是否设置为 false

  • HTTPS
  • SESSION_COOKIE_SECURE
  • CSRF_COOKIE_SECURE