Johnson
Hi I can see http://127.0.0.1:8000/static/credentials.json json codes in screen but I writed my py file with open credentials.json django gives me FileNotFoundError whyy??
# views.py from django.templatetags.static import static url = static('credentials.json') #returns the static path to the file # You can then open the file and parse it
Mike
Anyone have best video on restful API?
Anonymous
How is filter data according within to 10 kn range
Anonymous
I have try geodjango but its dependency libary not install
Anonymous
Use sqlite data base
Anonymous
Plz help me
Артем
how this url must be presented in urls.py? http://94.228.112.111/thanks?orderId=652a7043-05ee-7fe8-b48c-e3d027e6b5e0&lang=ru
Артем
such as? urlpatterns = [ path('add_order_click/', add_order_fast_click, name='add_order_fast_click'), path('add_order_click_basket/', add_order_click_basket, name='add_order_click_basket'), path('thanks/(?orderid=<slug:order>)/', thanks, name='thanks'), ]
Erik
Hey! Do anybody know how to display to unauthorized user datetime fileds somewhere in a template in his local timezone??
Erik
Inside official docs you can find an entire about setting timezone in Django
I already did. Does nothing. I need some dates and time in my template change dynamically. Depends on users browser timezone.
Erik
Whole day yesterday
Mirco
You need more time then Timezones are not easy 😊 But it's pretty easy to do it also inside the context To know the timezone from the browser you can just use vanilla JS and then with pytz or the new ZoneInfo you can convert times
Azizbek Xushnazarov
#Question I have a model that has a foreignkey for User model. And I have to get it's username. To do this, i have overrided the field declaration and set CharField(). But in this way I can only read data but cant create. How can I achive this? Or should I create separate serializers for reading and writing Model.
Y
Hi I use for loop for my list. list example data={"name":"John} I use This code `{% for i in username %} <span>{{username.i}}{{i}}</span><br> {% endfor %}` But username.i dont give me result , if I write username give me all list if I write i give me list key But I write as key value
Mahdi
Hello guys I wana learn django, can you share the good resources for learning?
Doragonsureiyā
Hello guys I wana learn django, can you share the good resources for learning?
Looking for Django tutorials? you can follow these three recommended ones: * Official documentation and tutorial * Tutorial from MDN * Tutorial from django-girls
MAK
May I know where to learn django
Maxim
May I know where to learn django
https://t.me/django/188088
Azizbek Xushnazarov
You can get the username using the user.username
I think you have no idea what I am talking about
Azizbek Xushnazarov
You have a model that have a attribute like user = ... Right?
yes i have a Task model has the field user = Foreignkey(User) If i serialize a task, user is just it's id. I want it's username to be serialized
Azizbek Xushnazarov
So i overrided user field in serializer like this: class TaskSerializer(ModelSerializer): user = StringRelatedField() but StringRelatedField is read only
William
If you just want the username you can do it like this user_username=serializers.CharField(null=True, source='user.username')
William
So i overrided user field in serializer like this: class TaskSerializer(ModelSerializer): user = StringRelatedField() but StringRelatedField is read only
Instead of StringRelatedField() create a new serializer class with a user model and pass it in the user field
Azizbek Xushnazarov
Azizbek Xushnazarov
cause the user field shoud get User instance not Charfield
ㅤㅤㅤㅤ ㅤㅤㅤ◡̈⃝ㅤㅤ ㅤㅤㅤㅤㅤㅤ ㅤㅤㅤ
yes i have a Task model has the field user = Foreignkey(User) If i serialize a task, user is just it's id. I want it's username to be serialized
You can use two ways for implementing serializer for related 1: Class UserSerializer(serializers.ModelSerializer): Class Meta: Model = User Fields = ['username'] Class TaskSerialzer(serializers.Serializer) user = UserSerializer() 2: TaskSerialzer(serializers.Serializer) user = serializers.SerializerMethodField('get_user') def get_user(self, obj): return obj.user.username
ㅤㅤㅤㅤ ㅤㅤㅤ◡̈⃝ㅤㅤ ㅤㅤㅤㅤㅤㅤ ㅤㅤㅤ
Azizbek Xushnazarov
it is supposed to be an id. but we override the field that now it require dictionary. that is why it is giving this error
Michael the wolf 🐺
Are there any opensource django web applications ? Rest api's
Michael the wolf 🐺
ok thnx
لزيز
Ok
Azizbek Xushnazarov
Creating what?
creating model instance ofc
William
creating model instance ofc
Creating user or other model data that has been used as a foreign key?
William
other
Share the error message you got.
Azizbek Xushnazarov
Share the error message you got.
'Invalid data. Expected a string, but got int.' this is when I use Charfield()
Azizbek Xushnazarov
user field gets id as an int when creating a task model instance. but Charfield does not like it.
Mirco
'Invalid data. Expected a string, but got int.' this is when I use Charfield()
You need a SerializerMethod and that method have to return obj.user.username
Сардор
how to edit existing pdf file and render to page ?
Mirco
it will be a read-only field then.
So just leave the user PK and inside the POST you have to pass the id and that's it
Mirco
Otherwise you need a nested serializer by using a UserSerializer ( example name )
Mirco
If your FK is called user Inside your model serializer you will have something like user = UserSerializer() Instead of a useless and wrong CharField
Azizbek Xushnazarov
So just leave the user PK and inside the POST you have to pass the id and that's it
sigh. But I want to serialize user.username, not it's pk
Azizbek Xushnazarov
nested serializer then 😊
In this case it serialize username and not pk and I love it. But I cant create model then 💀
Mirco
In this case it serialize username and not pk and I love it. But I cant create model then 💀
u have to override the create django allows u to do everything by using the OOP principles
Azizbek Xushnazarov
since it returns str() which is equal to username 😊
Mirco
I did ). But I chose CharField() with it
You will have troubles with it
priyanka
Jupyter*
Nayan
Hi I am facing issue while serving media files I am uploading files and it is going under media folder and it runs fine with local server But gives 404 error at Apache server
Nayan
Can anyone guide me why this is because of ??
Bye world
Which one should I lean first? Database or Django
Bye world
db
Thanks
Peaches
Hi guys I wanna build Online payment system like Stripe and Paypal in Django
Peaches
Could you please share any resources that might help
Azizbek Xushnazarov
Hi guys I wanna build Online payment system like Stripe and Paypal in Django
Django is not a good idea for that kind of projects
Peaches
Django is not a good idea for that kind of projects
I know but I want to build it in Django for demo purposes
Azizbek Xushnazarov
I know but I want to build it in Django for demo purposes
Are you familiar with Django. How good are you at it?
Peaches
Are you familiar with Django. How good are you at it?
I consider myself as intermediate level
Peaches
As of know I do not understand how things flow in online payment system
Azizbek Xushnazarov
As of know I do not understand how things flow in online payment system
It is not about just Django. There are a lot of work under Payment system. https://www.quora.com/How-hard-is-it-to-build-a-payment-system-like-Paypal. Before diving into creating backend I highly recomment to research first
Klaus
Actually I have doubt api..
Klaus
how its works ?
Klaus
i know to write code for api using drf but I do not how it is useful ?
Maxim
It is not about just Django. There are a lot of work under Payment system. https://www.quora.com/How-hard-is-it-to-build-a-payment-system-like-Paypal. Before diving into creating backend I highly recomment to research first
i wouldn't say that Django is easier than ANY payment system many payment systems have quite a developer-friendly interface (here I don't mean that Django interfaces are complicated, they are complicated as a whole) only poorly organized payment systems and cryptocurrencies can match Django in complexity this is just my personal opinion i implemented integration with one payment system in Django, and my experience with Django and programming in general is rather modest