Category : django-views

After going to the profile link: http://127.0.0.1:8000/basic_app/profile/3/ Then trying the link: http://127.0.0.1:8000/basic_app/profile/2/ It is working. So there must be some issue with primary key. And I figured out that this is happening after creating a superuser. models.py from django.db import models from django.contrib.auth.models import User # Create your models here. BLOOD_CHOICES = ( (‘o+’, ‘O+’), ..

Read more

I am building a copy of a social network with Django and Vanilla JS. I would like to edit posts asynchronously using the fetch API. In urls.py I’ve got an API route as follows: urlpatterns = [ … path("edit/<int:post_id>", views.edit, name="edit"), … ] In models.py the Post objects is as follows: class Post(models.Model): user = ..

Read more

I first created a custom user model by inheriting AbstratctBaseUser: from django.db import models from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin from django.utils import timezone from .manager import FirstManager #Making custom User model class MyRegistration(AbstractBaseUser, PermissionsMixin): location_list=[ (‘Solapur’, ‘Solapur’), (‘Latur’, ‘Latur’), (‘Dhule’, ‘Dhule’), (‘Akola’, ‘Akola’), (‘Nashik’, ‘Nashik’) ] username=models.CharField(max_length=10, unique=True) email=models.EmailField(unique=True) first_name=models.CharField(max_length=150) last_name=models.CharField(max_length=150) location=models.CharField(max_length=10, choices=location_list, default=’Latur’) designation=models.CharField(max_length=70) ..

Read more

drf—> CustomDBLogger—>customdblogger_views.py import getpass import socket import sys import time class Logger: def __init__(self): self.username = getpass.getuser() def LoggerParams(request): start = time.time() params = {‘user’: getpass.getuser(), ‘class_name’: request.__class__.__name__, ‘method_name’: sys._getframe().f_code.co_name, ‘module_name’: __name__, ‘ip_address’: socket.gethostbyname(socket.gethostname()), ‘process_time’: time.time() – start, } return params attributes = Logger().LoggerParams() I need to capture the class_name, method_name, module_name(app in which the ..

Read more

I created a custom user model by extending AbstractBaseUser: class MyRegistration(AbstractBaseUser, PermissionsMixin): location_list=[ (‘Solapur’, ‘Solapur’), (‘Latur’, ‘Latur’), (‘Dhule’, ‘Dhule’), (‘Akola’, ‘Akola’), (‘Nashik’, ‘Nashik’) ] username=models.CharField(max_length=10, unique=True) email=models.EmailField(unique=True) first_name=models.CharField(max_length=150) last_name=models.CharField(max_length=150) location=models.CharField(max_length=10, choices=location_list, default=’Latur’) designation=models.CharField(max_length=70) is_active=models.BooleanField(default=False) is_staff=models.BooleanField(default=False) start_date=models.DateTimeField(default=timezone.now) last_login=models.DateTimeField(null=True) USERNAME_FIELD=’username’ REQUIRED_FIELDS=[’email’, ‘first_name’, ‘last_name’, ‘location’, ‘designation’] objects=FirstManager() def __str__(self): return self.username And my manager loos something like this: ..

Read more

veiws.py from django.shortcuts import render,redirect from django.contrib.auth.models import User, auth from django.contrib import messages from travello.models import Destination import traceback from django.core.files.storage import FileSystemStorage # Create your views here. def login(request): if request.method == ‘POST’: username = request.POST[‘username’] password = request.POST[‘password’] user = auth.authenticate(username=username, password=password) if user is not None: auth.login(request,user) return redirect("/") else: messages.info(request,’invalid ..

Read more

i cant find solution to this simple problem. urls.py path(‘board/<id>/’, board, name="board"), views.py def index(request): if request.method == ‘GET’: usuario = request.user last_board = Usuario.objects.filter(user=usuario.id).values_list("last_board", flat=True) if usuario.is_authenticated: return redirect(‘/board/’, last_board ) return render(request, "index.html") i tried with get, post, without a request.method but its just simple dont pass the arguments, i literally have the ..

Read more