Acquaintance
Acquaintance
Habib
Oh! Thank you so much I'll look into that
The Inspired
Saransh
while setup what takes cares of packages installed,
Saransh
one created a folder and found some packages pre installed , how is it possible?
Saransh
i am working with v-env's
Khaled
I think you should use signals
Sintu
hello guys, can you suggest me
how to reduce the response time of Our Django REST Framework API
Api error - Bad Gateway Error Code 502
AB
Hello guys can I run two servers for the same front end
With the same database
Legend
Hello i am start learning django any youtube channel or free course
Charly
Pisey
cj
Hemanthkumar
Iam doing college management system project but the static page is not linking with templtes and idea how to link it
When i open the output it displays {%static%} in web browser any ideas guys how to reslove it
Alex
Andrew
Mmms
I have a issue in api
Mmms
ayone please help me
Mmms
TypeError at /api/accounts/login/validate_email_verification_status() got an unexpected keyword argument 'email'
Request Method:POSTRequest URL:http://localhost:8000/api/accounts/login/Django Version:4.2.11Exception Type:TypeErrorException Value:validate_email_verification_status() got an unexpected keyword argument 'email'Exception Location:C:\python\Wagon\Wagon_spin-main\Wagon_spin-main\django\lib\site-packages\dj_rest_auth\serializers.py, line 132, in validateRaised during:main.views.CustomLoginView
Mmms
from core.bonus_system import models
from core.users.exceptions import EmailNotVerified
from core.users.models import CustomUser, UserInfo
from core.users.services.services import generate_fake_user_info
from main.form import CustomPasswordResetForm
from main.loguru_settings import casino_logger
class CustomLoginSerializer(LoginSerializer):
def validate_email_verification_status(self, user: CustomUser) -> None:
if app_settings.EMAIL_VERIFICATION == app_settings.EmailVerificationMethod.MANDATORY:
email_address = None
try:
# user created by cashier doesn't have email at all
# so this verification is needed for users that registered themselves
email_address = user.emailaddress_set.get(email=user.email) # type: ignore
except ObjectDoesNotExist:
casino_logger.info(
"User's email does not exist entirely. Users made by cashier are trusted automatically",
)
if email_address is None:
return
if not email_address.verified:
raise EmailNotVerified
Mmms
problem in this user.emailaddress_set.get(email=user.email)
Mmms
please help me
Mmms
I dont have clear idea about it
emailaddress_set
Unknown
Who can recommend the Django CRUD boilerplate?
Priyanshu Pratap
Hello there...i just want to know how can i make static file inaccessible to the user like they don't inspect it and download or make a copy of that...also want to know is there is something like encoding static files??
Soft
hello Guys
My Django login authentication isnt working. i 've tried a lot of things but no better.
When i log the return values its does return the username but not the password
the registration works fine and registers users into the database. i use jetbrain Datagrip with mysql database
Melvin
Soft
Yes it submits through the registrations view which i can see in the database as hashed
Soft
in the login view, its always evaluates to username or password not correct
Melvin
Have you tried printing the form values in the login view?
Is the data correctly passed there?
Soft
it does print username and password in the terminal
Abolfazl
how can i define a function that flushes the entire request.session for me every x second
Doragonsureiyā
Urvil
Share static file configuration
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
STATIC_URL = 'static/'
STATIC_ROOT=os.path.join(BASE_DIR,'staticfiles')
STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]
amira
i am making patental control app using Django is it fine to make all the work in the admin panel without adding other urls to finish it ?
The Inspired
Mmms
Anyone can explain about abstractUser mobel to create customUser
Urvil
Charly
Alex
Alex
Khaled
Who can recommend the Django CRUD boilerplate?
have created a base view for CRUD operations in Django. You can check it out in my LinkedIn profile. I have improved this base view a little bit since this post. You can now add user roles and custom queries.
check it out
https://www.linkedin.com/feed/update/urn:li:activity:7176719392393547776?utm_source=share&utm_medium=member_desktop
michael
Kirill
Hello, I'm making a web service. There is a model in which users store data
class Users(models.Model):
user_id = models.AutoField(primary_key=True)
username = models.CharField(max_length=50)
email = models.EmailField(max_length=100, unique=True)
password_hash = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
role_id = models.ForeignKey(Roles, on_delete=models.SET_NULL, null=True)
def save(self, *args, **kwargs):
# Check if the password needs to be hashed
if not self.password_hash.startswith('pbkdf2_sha256$'): # Check for hash presence
self.password_hash = make_password(self.password_hash)
super().save(*args, **kwargs)
class Meta:
db_table = "users"
I use simplejwt for authorization
class LoginAPIView(APIView):
def post(self, request):
username = request.data.get("username")
password = request.data.get("password")
# Login Validation
if not username or not password:
return Response(
{"error": "Username and password are required"},
status=status.HTTP_400_BAD_REQUEST,
)
try:
# Get user by username
user = Users.objects.get(username=username)
except Users.DoesNotExist:
# If the user does not exist, return an error
return Response(
{"error": "User not found"}, status=status.HTTP_404_NOT_FOUND
)
# Check the password hash matches
if not check_password(password, user.password_hash):
# If the password is incorrect, return an error
return Response(
{"error": "Invalid credentials"}, status=status.HTTP_401_UNAUTHORIZED
)
# Generate an access token
refresh = RefreshToken.for_user(user)
tokens = {
"refresh": str(refresh),
"access": str(refresh.access_token),
}
# Returning tokens
return Response(tokens, status=status.HTTP_200_OK)
But it gives an error
ValueError: Cannot assign "<Users: Users object (6)>": "OutstandingToken.user" must be a "User" instance.
As I understand it, jwt is looking for user, but I’m using the users model
The Inspired
Hello, I'm making a web service. There is a model in which users store data
class Users(models.Model):
user_id = models.AutoField(primary_key=True)
username = models.CharField(max_length=50)
email = models.EmailField(max_length=100, unique=True)
password_hash = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
role_id = models.ForeignKey(Roles, on_delete=models.SET_NULL, null=True)
def save(self, *args, **kwargs):
# Check if the password needs to be hashed
if not self.password_hash.startswith('pbkdf2_sha256$'): # Check for hash presence
self.password_hash = make_password(self.password_hash)
super().save(*args, **kwargs)
class Meta:
db_table = "users"
I use simplejwt for authorization
class LoginAPIView(APIView):
def post(self, request):
username = request.data.get("username")
password = request.data.get("password")
# Login Validation
if not username or not password:
return Response(
{"error": "Username and password are required"},
status=status.HTTP_400_BAD_REQUEST,
)
try:
# Get user by username
user = Users.objects.get(username=username)
except Users.DoesNotExist:
# If the user does not exist, return an error
return Response(
{"error": "User not found"}, status=status.HTTP_404_NOT_FOUND
)
# Check the password hash matches
if not check_password(password, user.password_hash):
# If the password is incorrect, return an error
return Response(
{"error": "Invalid credentials"}, status=status.HTTP_401_UNAUTHORIZED
)
# Generate an access token
refresh = RefreshToken.for_user(user)
tokens = {
"refresh": str(refresh),
"access": str(refresh.access_token),
}
# Returning tokens
return Response(tokens, status=status.HTTP_200_OK)
But it gives an error
ValueError: Cannot assign "<Users: Users object (6)>": "OutstandingToken.user" must be a "User" instance.
As I understand it, jwt is looking for user, but I’m using the users model
your "Users" model is a normal model, not Django's default user model, which JWT picks up by default.
If you wish to use your own custom model as user model, then you have to override the default user model that Django provides:-
https://docs.djangoproject.com/en/5.0/topics/auth/customizing/#extending-the-existing-user-model
after creating this default user model, import this model to pass in JWT's 'for_user' method
The Inspired
Yes
try running `python manage.py collectstatic'?
Abolfazl
Ортонормированная
https://github.com/dura0ok/photocenter-django/blob/master/queries/views.py
hi guys, please advice, how i can refactor this duplicated code
The Inspired
Ортонормированная
The Inspired
The Inspired
plain django
gotcha.
One way to do it is to move all the logic inside the various QueryHandler methods to one single method and use a switch case to run method appropriately
Ортонормированная
Ортонормированная
i want make it more short, abstract
The Inspired
huh? of course you put break when you do use switch case lol
The Inspired
your codes are repeating in every single method
The Inspired
only 2 or 3 lines of logic and the template rendering is different
The Inspired
rest all are same... so it makes sense
The Inspired
to put them inside switch case and run 1 case at a time, depending on the input received
The Inspired
rather than write the same method multiple times.
kha ~
What type of rest api should be when i want to upload a image from website to databases, and the retrieve the photo also.
And what is the best solution to send and retrieve images in api.
amira
Tanjiro
Good day, can you guys helped me on how to add the edit function in my code? I keep having errors
https://nekobin.com/muwawapedu
Am i doing it right?
The Inspired
The Inspired
The Inspired
except you use serializers to serialize the image data
Tanjiro
Tanjiro
https://nekobin.com/ravisuhoqa