Andrew
Hi I learned django & made projects with it but if I want to make these projects with Django-Rest-Framework is the same process of development or it's different approach?? in order to be api developer
Himanshu
Hi guys anyone please help me how to count total product of a session
Himanshu
In django
Med M'bareck
.url
01110010
Its should be {% load static %} <img src="{% static 'accounts/alatoo.png' %}" alt="My image">
🧚‍♂️
{% load static %} <img src="{% static 'media/images/alatoo.png' %}" alt="My image">
Ashish
Please read about static files in django .. it will clear your doubts
01110010
You got to check your setting to point statics to your picture or asset STATICFILES_DIRS = ( ‘assets’,)
Jitxs
what is best practice just adding your app in installed app and use app/index.html and app/style.css or configuring the setting.py for templates and static ?
mohamedhk2
Hi, In Django, I created a custom backend located at MyApp/auth/MyCustomBackend.py and added it to the settings.AUTHENTICATION_BACKENDS. I added a print statement in the MyCustomBackend.authenticate function at the 1st line, but I am still getting "Invalid username or password" without any print statement. Can anyone help me figure out why?
01110010
Hi, In Django, I created a custom backend located at MyApp/auth/MyCustomBackend.py and added it to the settings.AUTHENTICATION_BACKENDS. I added a print statement in the MyCustomBackend.authenticate function at the 1st line, but I am still getting "Invalid username or password" without any print statement. Can anyone help me figure out why?
Check your print function You might unknowingly type print(username=username, password=password) which is bad. If that isn’t the case , I recommend you provide us more detail about your code Or check solutions on Django Documentation https://docs.djangoproject.com/en/4.2/topics/auth/customizing/
Muhammed
Hey i need a rest Django api that check a token from Google sso if valid Google token and user is existed ge can login but if token is valid but not an existed user it create account for him using Google
Vorke
Yes
Hello, thanks, i have managed
Nimra
Hi there.. I wanted to create custom error pages for my drf application. Do anyone have any idea about this?
bhzad
Hello, I redirected the user to the home page after logging in the file view, but after logging in, this does not happen, and the same login page is reloaded, but the user is logged in. How can I solve the problem? I even wrote login_redirect_url in the setting file, but it doesn't work
Shivam
Then homepage will show other otherwise go to login page
bhzad
i did this
Amicah
i did this
You first have to make sure home is your root url. Then add the @login before the home view. To make sure that before somebody goes to home they have to be logged in.
bhzad
You first have to make sure home is your root url. Then add the @login before the home view. To make sure that before somebody goes to home they have to be logged in.
I don't want what you said I want the user to enter the main page first and be able to see it, then I put a login button for him, after pressing the button, he will enter the login form, after completing the form, if the information is correct, he will be logged in. But if the information is correct and we log in, I want it to be redirected to home, but the user enters but remains logged in on the same page. I used a custom user for login and Django own login function
RXRX
{% for year in range(2010, 2021) %} {% for p in files %} {% if p.year|stringformat:"s" == year|stringformat:"s" %} Match found for year {{ year }}! <br> {% else %} No match found for year {{ year }}.<br> {% endif %} {% endfor %} {% endfor %} can someone tell me right approach, i dont want tu run the logic inside the loop again. i just want to print all years and print if file found or not found
hadi
hi , how can i set custom permissions for media and static files?
Jitxs
what is best practice just adding your app in installed app and use app/index.html and app/style.css or configuring the setting.py for templates and static ?
Павел
Hello everyone! Can anyone tell me if there is a tool that allows you to take an openapi schema in yaml format and, based on it, automatically generate a package for DRF with ready-made serializers? Specifically in this order, not the other way around, when you write a serializer and then generate an openapi specification from it. I found tools for Flask, FastAPI, but I don't see anything for the DRF and Django Something like this: https://openapi-generator.tech/docs/generators p.s. all I could find was the drf-yasg and swagger-django-generator. But they don't support openapi 3.0 and django > 4
Павел
drf-spectacular and it supports OAS 3
drf-spectacular is a tool that allows you to generate an openapi schema based on written serializers, routes and views And I need the reverse order: generation of a server package compatible with drf and django, based on the existing openapi specification For example, there is "openapi-generator", but it only allows you to generate server-side code for flask and fastapi
مريم خالد
how can i get only a foreign key of admin user in django without usual user? do anyone have an idea how can i do this?
.
how can i get only a foreign key of admin user in django without usual user? do anyone have an idea how can i do this?
No idea what you’re talking about. Try giving a sample data & output of what you want.
.
what is best practice just adding your app in installed app and use app/index.html and app/style.css or configuring the setting.py for templates and static ?
IMO by default the first one is the best practice. But if it’s customized then the second one can be better for you case.
Jitxs
IMO by default the first one is the best practice. But if it’s customized then the second one can be better for you case.
thanks i have seen that with my code that when i apply style.css it work and when i applied style1.css the css didn't applied while using the 1st method... is it some bug or ?
RXRX
do if p.year in range directly, no need for the outermost for year in range
worked out, right approach was to create new list in views.py. it is hard to create list and filter via loops in template.
Jitxs
Have you force refresh the page like Ctrl + F5?
nah but i have done reload ctrl+c and then run again
MHJ
hello guys i don't know why my content of render partial doesn't show in web ? who knows about it problem?
MHJ
No impossible to say without any detail
i did all step of render partail of my project Sidebar from PyPi.org but it didn't show in my localhost
MHJ
no errors but it don't show the details
Charly
what do u mean bro about 1 &2 ur Q
Show the code and tell us what you did tha part of "all steps" you mentioned
Charly
pypi.org/project/django-render-partial/
you should not use that library
Charly
has been not updated since 2018
MHJ
why?
MHJ
ok tnx bro
ibraheem
hi I want to create an educational system using Django, and I want to add a feature where, after the administrator approves the test results, a PDF certificate is generated for the student. How can I do this?
Doragonsureiyā
🚫 ‎Trey [6015038246] is already banned.
.
hi I want to create an educational system using Django, and I want to add a feature where, after the administrator approves the test results, a PDF certificate is generated for the student. How can I do this?
You’ll need to develop the Django application to handle all of that process, from the models, to the urls, to the views, and to the templates.
.
ok my question how to generate the pdf file
You can use reportlab, pdfmake, or others.
ibraheem
You can use reportlab, pdfmake, or others.
Can these files retain their file format after replacing the text?
ibraheem
i edit the template
.
Can these files retain their file format after replacing the text?
I don’t understand, please explain what you’re talking about
ibraheem
I don’t understand, please explain what you’re talking about
whin edet the text in the template is pypdf2 or ather change the text format
.
whin edet the text in the template is pypdf2 or ather change the text format
Yes, you can style them. It’s not exactly the same process as styling using HTML and CSS, so you’ll need to check the documentation on how to do it.
Miqo
Hi I want to get 5 random objects from my query How can i do that?
.
Hi I want to get 5 random objects from my query How can i do that?
https://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by “To order randomly, use "?", like so: Entry.objects.order_by("?") Note: order_by('?') queries may be expensive and slow, depending on the database backend you’re using.”
Kritesh
If it’s react functional component; inside of ur useEffect function Use Axios to get data from Django url
Bro we have integrated django and react and i am access his pages by it build version of index.html template
Kritesh
Issue is rest of react pages it's required data to access rest of pages means if I pass token as get request he will bee hitting api to get data after tht I can able to go rest of pages
Kritesh
So I want to do it as server side approach broo
Farzin
Hello every one, In our panel we have multiple event, each event has a map with multiple area, when we click on one of the areas some data will be shown, we needed these data to be updated each time some one click on each of the areas before the are represent the data, what I did was override the to_represention method of django rest to check based on some parameters that comes from user and update the data related on that area on database, it was working without problem on Test system, but now in production I'm facing: maximum recursive error from queryset, why this happens?
DoT
hi everyone im getting error csrf token request aborted i added csrf token after post method in form ,...it works fine and page opens(every 1st time when i click login) when i reload the page and resubmitting the form it shows the csrf request error(every time when i reload or resubmit) anyone can help me??.....
DoT
its the code im getting error of csrf ....2nd time submission
Shafin
I have a form with add multiple cities when I click add increment cities input only after insertion I need to update I I give 2 cites then edit and add one more that time update pervious values and insert new cities
Shafin
Help me with this