Проблема с входом на джанго, как реализовать в моем случае?

Уменя есть модель account с данными пользавателей. Когда я в views.py проверяю есть ли в базе данных логин и пороль похожий на тот что ввел пользаватель на сайте, если есть такие данные я создаю contextlogin = request.POST['login'],и передаю эту переменую в html и через jinja проверяю для получение данных имено этого человека. Но проблема в том что каждый пользаватель заходит и contextlogin перезаписываеться и у других пользавателей после перезагрузки страницы меняються данные , как это можно исправить?

Views.py :
def main(request):
    global contextlogin
    global context
    if request.method == "POST":
        for i in account.objects.all():
            if i.account_login == request.POST['login']:
                if i.account_password == request.POST['password']:
                    context = account.objects.all()
                    contextlogin = request.POST['login']
    return render(request, "fr/main.html")

def profile(request):
    global context
    global contextlogin
    return render(request, "fr/profile.html", {'context': context, 'contextlogin': contextlogin})


main.html:

<form action = "" method = 'POST'>
    {% csrf_token %}
    <div id = 'login'>
        <p title = 'Вход в аккаунт' style = 'text-align: center; margin-left: -30px;'>Вход в аккаунт</p>
        <input placeholder="Ваш логин" id = 'id_login' name = 'login' type = 'text' style = 'width: 200px; height: 35px; margin-left: 130px;' required>
        <input placeholder="Ваш пороль" id = 'id_password' name = 'password' type = 'password' style = 'width: 200px; height: 35px; margin-left: 130px; margin-top: 10px;' required>
    <button title = 'Проверить и войти' type = 'submit' style = 'background-color: rgb(26, 66, 18); color: red; width: 220px; height: 35px; margin-left: 130px; margin-top: 10px;' required>Войти</button>
        <br>
        <br>
        <a title = 'Восстоновите ваш аккаунт!' href = "{% url 'forgot' %}" style = 'color: black; margin-left: 175px; margin-top:10px;'>Забыли пороль?</a>
        <br>
        <br>
        <a title = 'Впервые тут? Зарегестрируйтесь..' href = "{% url 'addaccount' %}" style = 'color: black; margin-left: 172px; margin-top:10px;'>Создать аккаунт</a>
    </div>
    </form>


profile.html:
{% for i in context %}
        {% if i.account_login == contextlogin %}
        <p style = 'color:rgb(10, 10, 10);  margin-top: 10px; margin-left: 500px;'>Ваш профиль</p>
        <div id = "Widget">
            <img style = 'margin-left: 52px; margin-top: -10px;' onclick = "" width = '40' height = '30' src = {{i.account_image.url}}>
            <br>
            <a style = 'text-decoration: none; margin-left: 18px; color:rgb(247, 242, 242);' href = ''>Мой профиль</a>
            <hr>
            <img style = 'margin-left: 52px; margin-top: 5px;' onclick = "location.href = ''" width = '40' height = '30' src = '../../../static/images/postinfo.png'>
            <a style = 'text-decoration: none; margin-left: 38px; color:rgb(247, 242, 242);' href = ''>Главная</a>
            <hr>
            <div id = "Profile">
                <img width = '200' height = '200' src = {{i.account_image.url}}>
                <br>
                <form action = '' method = "POST">
                {% csrf_token %}
                <div class="input__wrapper">
                    <input name="file" type="file" name="file" id="input__file" class="input input__file" multiple required>
                    <label for="input__file" class="input__file-button">
                    <span class="input__file-button-text">Выберите фото</span> 
                    </label>
                 </div>
                <button style = 'width: 120px; height: 30px; margin-left: 40px; margin-top: -9px; background-color: rgb(17, 240, 9);' type = 'submit'>Сохранить</button>
                 </form>
                 <br>
                <p style = 'margin-left: 210px; margin-top: -285px;'> <strong>{{i.account_name}} {{i.account_surname}}</strong></p>
                <div id = 'Tick'></div>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Логин: </p>
                <p style = 'color: rgb(10, 34, 250); margin-left: 380px; margin-top: -35px;'> {{i.account_login}}</p>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Email: </p>
                <p style = 'color: rgb(10, 34, 250); margin-left: 380px; margin-top: -35px;'> {{i.account_email}}</p>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Номер телефона: </p>
                <p style = 'color: rgb(10, 34, 250); margin-left: 380px; margin-top: -35px;'> {{i.account_number}}</p>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Пороль: </p>
                <p onclick = "location.href = ''" style = 'color: rgb(250, 3, 3); margin-left: 380px; margin-top: -35px;'> редактировать</p>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Ваш возраст: </p>
                <p style = 'color: rgb(10, 34, 250); margin-left: 380px; margin-top: -35px;'> {{i.account_old}} лет</p>
                <div id = "Tick"></div>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Страна: </p>
                <p style = 'color: rgb(10, 34, 250); margin-left: 380px; margin-top: -35px;'> {{i.account_country}}</p>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Город: </p>
                <p style = 'color: rgb(10, 34, 250); margin-left: 380px; margin-top: -35px;'> {{i.account_city}}</p>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Пол: </p>
                <p style = 'color: rgb(10, 34, 250); margin-left: 380px; margin-top: -35px;'> {{i.account_sex}}</p>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Увлечения: </p>
                <p style = 'color: rgb(10, 34, 250); margin-left: 380px; margin-top: -35px;'> {{i.account_hobby}}</p>
                <p style = 'margin-left: 210px; margin-top: 5px;'> Сайт: </p>
                <p onclick = "location.href = '{{i.account_weburl}}'" style = 'color: rgb(250, 10, 62); margin-left: 380px; margin-top: -35px;'> {{i.account_webname}}</p>
                <div id = 'Tick'></div>
                <br>
                <a href = '' style = 'text-align: center; margin-left: 300px;'> Редактировать аккаунт </a>
            </div>
        </div>
        {% endif %}
        {% endfor %}


Надеюсь вы меня поняли()
  • Вопрос задан
  • 66 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
17 апр. 2024, в 00:48
35000 руб./за проект
17 апр. 2024, в 00:13
800 руб./за проект
17 апр. 2024, в 00:06
240000 руб./за проект