nyctophile
Hi guys!
so I wanted to use built in LoginView and it is not working, but if i use function based login view it's working perfectly.
here is my code https://hastebin.com/share/epayetoror.bash
am i missing something here?
any help appreciated and thanks in advance!
Denys
Hi guys. can you help me what to do if I can’t access the database Django, it says there is a connection error, what should I do?
Muflone
Никита👨💻
hi, I make a POST request through a regular generics.ListCreateAPIView with this JSON(application/json):
{
"category_ref": "55b70f9e-7a75-48c9-81e4-e40bf7a9ac6e",
"name": "gggg",
"prices": [
{
"price": 777.00,
"size_description": "zzz"
}
]
}
=> status ok
But if I want to do the same thing with formData(multipart/form-data)
category_ref:55b70f9e-7a75-48c9-81e4-e40bf7a9ac6e
name:gggg
prices[0][size_description]:777.00
prices[0][price]:zzz
=> status 400
{
"prices": [
{
"size_description": [
"This field is required."
],
"price": [
"This field is required."
]
}
]
}
where did I go wrong?
serializers:
class MenuItemSerializers(serializers.ModelSerializer):
owner = serializers.HiddenField(default=serializers.CurrentUserDefault())
prices = MenuItemPriceSerializers(many=True, )
def create(self, validated_data):
prices = validated_data.pop('prices')
menu_item=MenuItem.objects.create(**validated_data)
for price in prices:
MenuItemPrice.objects.create(menu_item_ref=menu_item, **price)
return menu_item
def update(self, instance, validated_data):
instance.name = validated_data.get('name', instance.name)
instance.image = validated_data.get('image', instance.image)
instance.save()
prices = validated_data.pop('prices', [])
for price in prices:
price_id = price.get('id', None)
if price_id:
price_instance = MenuItemPrice.objects.get(id=price_id)
price_instance.price = price.get('price', price_instance.price)
price_instance.save()
return instance
class Meta:
model = MenuItem
fields = "__all__"
def validate_owner(self, value):
restaurateur = Restaurateur.objects.get(user=value)
return restaurateur
Никита👨💻
hi, I make a POST request through a regular generics.ListCreateAPIView with this JSON(application/json):
{
"category_ref": "55b70f9e-7a75-48c9-81e4-e40bf7a9ac6e",
"name": "gggg",
"prices": [
{
"price": 777.00,
"size_description": "zzz"
}
]
}
=> status ok
But if I want to do the same thing with formData(multipart/form-data)
category_ref:55b70f9e-7a75-48c9-81e4-e40bf7a9ac6e
name:gggg
prices[0][size_description]:777.00
prices[0][price]:zzz
=> status 400
{
"prices": [
{
"size_description": [
"This field is required."
],
"price": [
"This field is required."
]
}
]
}
where did I go wrong?
serializers:
class MenuItemSerializers(serializers.ModelSerializer):
owner = serializers.HiddenField(default=serializers.CurrentUserDefault())
prices = MenuItemPriceSerializers(many=True, )
def create(self, validated_data):
prices = validated_data.pop('prices')
menu_item=MenuItem.objects.create(**validated_data)
for price in prices:
MenuItemPrice.objects.create(menu_item_ref=menu_item, **price)
return menu_item
def update(self, instance, validated_data):
instance.name = validated_data.get('name', instance.name)
instance.image = validated_data.get('image', instance.image)
instance.save()
prices = validated_data.pop('prices', [])
for price in prices:
price_id = price.get('id', None)
if price_id:
price_instance = MenuItemPrice.objects.get(id=price_id)
price_instance.price = price.get('price', price_instance.price)
price_instance.save()
return instance
class Meta:
model = MenuItem
fields = "__all__"
def validate_owner(self, value):
restaurateur = Restaurateur.objects.get(user=value)
return restaurateur
class MenuItemPriceSerializers(serializers.ModelSerializer):
owner = serializers.HiddenField(default=serializers.CurrentUserDefault())
id = serializers.UUIDField(read_only=False, required=False)
class Meta:
model = MenuItemPrice
fields = "__all__"
read_only_fields = ('menu_item_ref',)
def validate_owner(self, value):
restaurateur = Restaurateur.objects.get(user=value)
return restaurateur
nyctophile
hey there!
have a quick question...
authenticated_user = authenticate(request, username=username, password=password)
why could authenticated_user be None while user exists, username and password is right?
Believe
yashu
Can we run the code without giving path in the template...
Mohammad
lets assume you are receiving username and password from the post method, then authentication and login logic will be
from django.contrib.auth import authenticate, login
def login(request):
username = request.POST.get('username',None)
password = request.POST.get('password', None)
user = authenticate(username=username, password = password)
if user is not None:
# creds are correct
login(request, user)
return redirect('.....') # redirect to your protected view
else:
# creds are not correct
return render(request, 'login.html',{})
Rose
hi, I make a POST request through a regular generics.ListCreateAPIView with this JSON(application/json):
{
"category_ref": "55b70f9e-7a75-48c9-81e4-e40bf7a9ac6e",
"name": "gggg",
"prices": [
{
"price": 777.00,
"size_description": "zzz"
}
]
}
=> status ok
But if I want to do the same thing with formData(multipart/form-data)
category_ref:55b70f9e-7a75-48c9-81e4-e40bf7a9ac6e
name:gggg
prices[0][size_description]:777.00
prices[0][price]:zzz
=> status 400
{
"prices": [
{
"size_description": [
"This field is required."
],
"price": [
"This field is required."
]
}
]
}
where did I go wrong?
serializers:
class MenuItemSerializers(serializers.ModelSerializer):
owner = serializers.HiddenField(default=serializers.CurrentUserDefault())
prices = MenuItemPriceSerializers(many=True, )
def create(self, validated_data):
prices = validated_data.pop('prices')
menu_item=MenuItem.objects.create(**validated_data)
for price in prices:
MenuItemPrice.objects.create(menu_item_ref=menu_item, **price)
return menu_item
def update(self, instance, validated_data):
instance.name = validated_data.get('name', instance.name)
instance.image = validated_data.get('image', instance.image)
instance.save()
prices = validated_data.pop('prices', [])
for price in prices:
price_id = price.get('id', None)
if price_id:
price_instance = MenuItemPrice.objects.get(id=price_id)
price_instance.price = price.get('price', price_instance.price)
price_instance.save()
return instance
class Meta:
model = MenuItem
fields = "__all__"
def validate_owner(self, value):
restaurateur = Restaurateur.objects.get(user=value)
return restaurateur
Rule 5️⃣: To share code or error tracebacks, use an online pasting service like:
- https://dpaste.org
- https://hastebin.com
- https://nekobin.com
- https://bin.kv2.dev
If you posted a wall of text, go back and delete it.
nyctophile
Sunil
hii friends, if anyone has integrated the payment gateway on phone in python django then please send me the zip file.
If you have created Server to Server Callback API then send its zip file also.
Jimmies San
Anonymous
I have an client. it send socket connect to Django 。but how can I consume this socket connections.(where can I put my socket sever into Django)
Rose
Anonymous
sorry for my English
Maxim
sorry for my English
it's not the language, it's that you didn't elaborate enough on the question
Anonymous
there are two py files. one is client another is sever . users use client.py socket to sever.py(IP ,Port)。
now I use django to manage users。
can I put the sever.py into Django, and how ? the sever.py work to listening some port and receive files
Anonymous
maybe it's TCP .Django is http .no answer.
Brook
Jimmies San
You need to understand what you are doing before proceeding further
Rose
User Amin has 1/3 warnings; be careful!
Reason:
speak ENGLISH only
Amin
Hi guys, ،İ have some problem in deploy django on my VPS, anyone can help me?
Jimmies San
Anonymous
Channel got it
Amin
Don't ask to ask, just ask.
İ'm trying to deploy my project on VPS via cpanel, before starting python app it is showing page below for my domain, then when i start python app it gives me error 503 instead of passenger_wsgi.py content
Amin
Oh no, i cant send photo here😵💫
Amin
Maxim
Oh no, i cant send photo here😵💫
that's right, portraits, landscapes and still lifes have nothing to do with programming
read the rules how to share code and errors
Данил
Hello, recommend please library to store info about user's Country,District,City, Address. And of course with ability represent it perfectly in front-end
Kumar Shreyansh
Rose
User Jeevan has 1/3 warnings; be careful!
Reason:
useless messages
Данил
Jimmies San
Rose
User Oguti has 2/3 warnings; be careful!
Reason:
do not send PMs without the recipient's consent; ask the person in the group first (rule #9)
Данил
Jimmies San
Rose
User Kevin Alex has 1/3 warnings; be careful!
Reason:
insisting on offtopic
nyctophile
hi guys,
I am having a problem with authentication..
i created a simple project, and created custom user model using AbstractUser
added my app , added templates dir, and AUTH_USER_MODEL='main.Usermodel' in settingss.py
I am using CreateView and LoginView in class based views, when i submit new user will get created, but i am still not loged in, even if i try to login with username and password same problem
here is my code, i do not know what i did wrong, on console there is no error
https://hastebin.com/share/uwojuzevay.bash
Can anyone help with that, thanks in advance!
Rose
User Рита has 1/3 warnings; be careful!
Reason:
rule #1: speak English
Prasanth
Anyone know about sso ( single sign on) on django rest framework? How can i implement it ?
nyctophile
hi guys,
I am having a problem with authentication..
i created a simple project, and created custom user model using AbstractUser
added my app , added templates dir, and AUTH_USER_MODEL='main.Usermodel' in settingss.py
I am using CreateView and LoginView in class based views, when i submit new user will get created, but i am still not loged in, even if i try to login with username and password same problem
here is my code, i do not know what i did wrong, on console there is no error
https://hastebin.com/share/uwojuzevay.bash
Can anyone help with that, thanks in advance!
Can anyone help with that, pls?
A
How to prevent login of multiple user with same username in django? Any one guide pl.
Mirco
Believe
Rose
User Bacanero has 1/3 warnings; be careful!
Reason:
rule #1: speak English
Rose
User Max has 1/3 warnings; be careful!
Reason:
this not a job board
Mirco
Rose
User Sobowale has 1/3 warnings; be careful!
Reason:
crossposting
Alisher
hi i need help with token issue
Alisher
Does anyone understand?
Kevin
could you provide more information about your problem ?
Charly
Does anyone understand?
No, no with the explanation of the issue you gave. So better if you explain properly.
Maxim
🏅♐Mark
How to create a model class for a unique username
Artem
🏅♐Mark
Why?
For retrieving the data
🏅♐Mark
I want to store unique usernames
Artem
What exactly do u need?
U should provide more details
🏅♐Mark
Actually I am developing a website for my shop so my plan is to recover user details using there username so that I need to create a unique username field
Artem
🏅♐Mark
🏅♐Mark
🏅♐Mark
Artem
What is .....
What's unclear?
Firslty, u make a model, than u describe a fields.
About models - https://docs.djangoproject.com/en/5.0/topics/db/models/
About ur question - https://stackoverflow.com/questions/48881838/django-user-model-username-unique-false
And please, google how to ask a questions. It'll help you and others in future
🏅♐Mark
A
Hi guys, tell me how to check if localization, internationalization works in the Django Rest Framework, please
Rose
User Aysel has 1/3 warnings; be careful!
Reason:
useless offtopic message (rule #3)
Vitaly
Hello, everyone
How is it possible to get values in expression GeneratedField for ForeignKey and ManyToMany fields?
total_weight = models.GeneratedField(verbose_name="Some name", expression=F('person.weight') + ... didn't work
It says: Cannot resolve keyword 'person.weight' into field.