با سلام دوباره من داخل فایل ویوهای یک اپ این کد ها رو دارم:
مشکل اینجاست که در کد html سه تا شرط وجود دارد و اولی و دومی کار می کنند اما سومی اصلا انگار متغیر را دریافت نمیکند من elif را هم امتحان کردم حتی شرط سوم را حذف کرده و به صورت and به شرط دوم ادغام کردم اما مثل اینکه اصلا نمیتواند متغیر را دریافت کند .
پیشاپیش با تشکر
#views.py
def login_page(request):
if request.method == "POST":
Login_Form = login_form(request.POST)
if Login_Form.is_valid():
username = request.POST.get('username_email')
password = request.POST.get('password')
user_auth = authenticate(user_username=username, password=password)
checked_username = User.objects.filter(
username__iexact=username).exists()
user_auth_bool = bool(user_auth)
checked_username_bool = bool(checked_username)
if user_auth_bool:
login(request, user_auth)
return redirect(reverse("index_page"))
if not user_auth_bool:
if checked_username_bool:
Login_Form.add_error(
"username_email", "your account is not active please activate it by the email link")
qq = True
# Login_Form.add_error("username_email", mark_safe(
# "<a class=didnt_get_code href=%s >Didnt get code!</a>" % escape("{%urls 'configuration_page' %}")))
if not checked_username_bool:
Login_Form.add_error(
"username_email", "Username or Email or Password is incorrect!")
if request.method == "GET":
Login_Form = login_form()
return render(request, "login/login.html", {
"login_form": Login_Form
})
#templates.example.html
<head>
{% load static %}
<title>Login</title>
<link rel="stylesheet" href={% static 'login/Styles/Login_Styles.css' %} type="text/css" />
<link rel="icon" href={% static 'login/Images/login.png' %} type="png" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css" />
</head>
<body>
<div class="wrong_data_alert {% if login_form.errors %}making_form_visible{% endif %}">
{% if not user_auth_bool %}
{% if checked_username_bool %}
<ul class="errorlist"><li><a class="didnt_get_code" href="{% url 'configuration_page' %}" >Didnt get code!</a></li></ul>
{% endif %}
{% endif %}
{{login_form.password.errors}}
{{login_form.username_email.errors}}
</div>
<div class="login_style">
<form method="post" id="login_form" action="{% url 'login_page' %}">
{% csrf_token %}
{{login_form.username_email}}
{{login_form.password}}
<i class="bi bi-eye-slash" id="togglePassword"></i>
<br />
<input class="remember_me_checkbox" type="checkbox" name="remember me" value="r_m" />
<label class="indented-checkbox-text">Remember Me</label>
<input class="login_page_button" type="submit" name="submit" value="Login" />
</form>
<div>
<a class="didnt_get_code" href={% url 'configuration_page' %} >Didnt get code!</a>
<a target="_blank" class="create_account_button" href={% url 'register_page' %}>CreateAccount</a>
</div>
</div>
<script src={% static 'login/Js/login.js' %}></script>
</body>سلام خدمت شما دوست عزیز
در این کدی که ارسال کردین صرفا 2 گزاره شرطی وجود داره دوست من
این دو مورد مشکل دارن؟
شرط اول در خط بالایی اون دو گزاره شرطی که دیدید -->
<div class="wrong_data_alert {% if login_form.errors %}making_form_visible{% endif %}">
checked_username_bool = bool(checked_username)
این کد نیازی نیست دوست من
خود جنگو بر اساس دستور exists یک boolean بر میگردونه و نیازی نیست تبدیلش کنین
من این کار رو انجم دادم ولی مثل اینکه فایده نداره کلا متغیر داخل شرط سوم رو true در نظر میگیره حتی اگر توی فایل ویو falseبشه(با دستور print از داخل فایل دیدم به false میشه)
لطفا سورس پروژه رو بدون پوشه ی venv در سایت mega.nz آپلود کرده و لینک دانلود رو ارسال کنین تا بررسی بشه