Acquaintance
Maybe you're saving the order and then making relations (ForeignKey) for orderproduct So when it's not related yet you're getting nothing
As an idea is to save the order and then relate orderproducts to it in your views.py When it's done, do your stuff
Acquaintance
Maybe you're saving the order and then making relations (ForeignKey) for orderproduct So when it's not related yet you're getting nothing
But the thing is that when you get this object "created", nothing might be related to it at the time
Habib
Oh! Thank you so much I'll look into that
The Inspired
it's the easy way there are others
I mean... if they want to go the hard way, then by all means 👍
The Inspired
I've ran into this issue a while back but I don't think wiping the DB did good, deleting the migrations did but it was stubborn for a while... The table already exists is truely RIP lol
Yeah...earlier, I used to keep migrations and wipe just the DB data. But then I faced problems down the line. so I just went with complete wipeout of both migrations and DB
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
Doragonsureiyā
Hello i am start learning django any youtube channel or free course
Looking for Django tutorials? you can follow these three recommended ones: * Official documentation and tutorial * Tutorial from MDN * Tutorial from django-girls
AB
Yes, but why the same database?
I am working on a hospital management project and I need an AI model using python So it should be on the same db
cj
Hello guys can I run two servers for the same front end With the same database
what do you exactly mean by "run two servers"?
Khaled
I am working on a hospital management project and I need an AI model using python So it should be on the same db
Yes, you can. Just change the port number for the second server. For the database, use the db_table in the Meta class in your model. However, you have to be careful, as that may cause data inconsistency in your database.
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
Urvil
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
I have somewhat similar problem I'm doing ecommerce project and i have decided to change template so when I changed template and put all necessary file in static folder, output page still looks basic, no css file and some images are not loading
Andrew
The problem is static files configuration
Check your settings for serving the static files
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
† n06h
Hello i am start learning django any youtube channel or free course
Search on YouTube, try django series by Justin Mitchell thank me later
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
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
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
it does print username and password in the terminal
Um... what is your problem? That your password isn't being saved to the DB?
Mmms
Anyone can explain about abstractUser mobel to create customUser
Alex
Anyone can explain about abstractUser mobel to create customUser
You are provided base model which you can use to extend and implement your own custom user model
Alex
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??
you can attach token to put time limit , but that still isn't enough to stop someone from manually inspecting or scraping your website and making a offline copy of everything static.
Alex
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 ?
django admin isn't supposed to be used that way, use permission levels and custom views for that.
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
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??
I saw something on sam kamkar(the hacker) website.. you can't inspect his website... Idk if that's what you wanted to achieve but you can check it out...   samy.pl
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'?
The Inspired
Can Anyone Help Me ???
what have you tried to do until now?
Ортонормированная
https://github.com/dura0ok/photocenter-django/blob/master/queries/views.py hi guys, please advice, how i can refactor this duplicated code
Abolfazl
what have you tried to do until now?
Actually, Nothing. That was my last goal :D
Ортонормированная
The Inspired
Actually, Nothing. That was my last goal :D
come back when you try something
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.
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
except you use serializers to serialize the image data
Tanjiro
https://nekobin.com/ravisuhoqa