|
views.py (login va register uchun) dastur kodidan namuna
|
bet | 9/10 | Sana | 26.07.2024 | Hajmi | 2,55 Mb. | | #268679 |
Bog'liq BMI3.views.py (login va register uchun) dastur kodidan namuna:
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.db.models import Sum
from django.db.models.functions import Coalesce
from django.shortcuts import render, redirect
from django.contrib import messages
# Create your views here.
from django.shortcuts import get_object_or_404
from apps.forms import LoginForm, RegisterForm
from apps.models import Product, Category, CartItem
def register(request):
if request.method == ‘POST’:
forms = RegisterForm(request.POST)
if forms.is_valid():
forms.save()
else:
print(forms.errors)
return redirect(‘login’)
return render(request, ‘auth/auth.html’)
def login_1(request):
if request.method == ‘POST’:
forms = LoginForm(request.POST)
if forms.is_valid():
username = forms.data.get(‘username’)
password = forms.data.get(‘password’)
users = authenticate(username=username, password=password) if users:
login(request, users)
return redirect(‘index_view’)
5.script.js dastur kodidan namuna:
"use strict";
(function () {
// Global variables
let
userAgent = navigator.userAgent.toLowerCase(),
isIE = userAgent.indexOf("msie") !== -1 ? parseInt(userAgent.split("msie")[1], 10) : userAgent.indexOf("trident") !== -1 ? 11 : userAgent.indexOf("edge") !== -1 ? 12 : false;
// Unsupported browsers
if (isIE !== false && isIE < 12) {
console.warn("[Core] detected IE" + isIE + ", load alert");
var script = document.createElement("script");
script.src = "./js/support.js";
document.querySelector("head").appendChild(script);
}
initialDate = new Date(),
$document = $(document),
$window = $(window),
$html = $("html"),
$body = $("body"),
isDesktop = $html.hasClass("desktop"),
isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
function lazyInit(element, func) {
var scrollHandler = function () {
if ((!element.hasClass(‘lazy-loaded’) && (isScrolledIntoView(element)))) {
func.call();
element.addClass(‘lazy-loaded’);
}
|
| |