Anonymous
how can i show my django admin blog functionality into my homepage like writing blog and many more
Бакыт
Guys, Can you please advise what could be problem with my detail url?It is working o.k with some objects but with some of them it is directing to non-existing object id or id of different object http://127.0.0.1:8000/flat/flat/7/ I have max 5 objects and ids are(1,2,3,4,5) def flatDetail(request, pk): flat = Flat.objects.get(pk=pk) print(pk) return render(request, 'flat_detail.html', locals()) urlpatterns =[ path('flat/<int:pk>/',views.flatDetail, name='flat_detail'),
Loki
Does anyone have example of project using django-rq?
mark
Hi
Бакыт
Change the variable name from ok to something like flat_id to make it more unique. It might be conflicting.
You mean from pk to flat_id?Previously it was like this def flatDetail(request, flat_id): flat = Flat.objects.get(id=flat_id) url(r'^flat/(?P<flat_id>\d+)/$', views.flatDetail, name='flat_detail'), then i tried with pk,but the same thing.
Adil
Hi everybody. Im making an app where people will share files and download it. It will be used for my university class. So, Ive learned how to upload files. But how can I list all the files for users to see them and ve able to download it?
Adil
i tried to use Document. objects.all() but this is meaningless didnt work
Rohan
And why it's meaningless ?
Cuz it didn't work for him, so it's meaningless 😂
Rohan
Be annoying and you'll be banned here too 🤷‍♂
George
No
Adil
Share your code so we can help u better
i will try to solve it myself. If i cant, i will share the code. Thanks)
Shubham
Hello there I have a query
Shubham
How can I create sign up form in such a way that..once a form has been filled and submitted by user (teacher / student) . The form should be sent to the Admins email id , once s/he verified the sign up form , the user should able log in
Anonymous
I have a very stupid question. Why do django needs the complex extra setup to deploy it on server. Why can't we simply do python migrate.py runserver to host it? How does it run locally without setting up all those extra apache / wscgi etc?
Oleg
I have a very stupid question. Why do django needs the complex extra setup to deploy it on server. Why can't we simply do python migrate.py runserver to host it? How does it run locally without setting up all those extra apache / wscgi etc?
1. runserver is a single-threaded server. You need multiple threads to serve multiple clients simultaneously. 2. You have to offload static serving to something more efficient, like nginx, so Django wouldn't have to spend time it could use to do actual work. 3. You'll probably eventually want to fine-tune your server (ssl, caching etc). You can't do that with runserver.
Oleg
I believe this question was asked and answered many times before, and I didn't have to, but I wanted to recollect my knowledge.
Anonymous
I want to render high quality interactive charts on my web app. Any suggestion for what library to use? I have had used plotly long ago for creating charts so have some experience with that. But it seems I need to render it in iframe to keep all functionalities. Looking for some native experience
Anonymous
Chart.js
Loki
Hello everyone. Sorry, that it's more python than django question, but it's very important So, I'm trying to use wkhtmltopdf to convert html file to pdf. I pulled it's docker and followed instructions from here https://hub.docker.com/r/openlabs/docker-wkhtmltopdf-aas/ Everything works fine if I do it using curl command. But I need to use it in my application, so I tried to do it using python request as in example. But now I can't correctly encode my html file. If i do 'contents': open('/file/to/convert.html').read().encode('base64') I get base64' is not a text encoding use codecs.encode() error. What can I do to encode html properly or maybe there is a way to "translate" curl command to python request?
R
Anyways, is there some reason you want use it as an external service instead of the existing django package?
R
https://django-wkhtmltopdf.readthedocs.io/en/latest/
Loki
Doesn't work (or maybe I messed things up). base64.b64encode need strings as parameters and I desperately tried file = open('...1.hmtl') and then passed it like str base64.b64encode(str(file), 'utf-8') it didn't work
Loki
I have to use wkhtmltopdf sadly
R
https://django-wkhtmltopdf.readthedocs.io/en/latest/
Yeah, but this package also allows you to use it without the need of having to do requests to another service
Loki
Oh, yeah, my bad, confused it with something else. But still if I try to base64.b64encode(file, 'utf-8') (in that case file = open('...1.hmtl')) I get TypeError: a bytes-like object is required, not '_io.TextIOWrapper' if I open it with 'rb' parameter I get TypeError: a bytes-like object is required, not '_io.BufferedReader'
DropDout
am facing this error
DropDout
raise ImproperlyConfigured("Empty static prefix not permitted") django.core.exceptions.ImproperlyConfigured: Empty static prefix not permitted
DropDout
when uploading media in ubuntu
DropDout
please help me
Mirco
Did you set MEDIA_URL and MEDIA_ROOT in your settings ?
DropDout
yes
DropDout
MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Mirco
Have you set STATIC_URL and STATIC_ROOT as well ?
DropDout
yes
Mirco
Your DEBUG is False or True ?
DropDout
okey...
DropDout
its FALSE
Mirco
you should use static() when DEBUG is True
Mirco
It's for development purpose
Mirco
When DEBUG is False , use a web server like nginx to serve media and static
raghvendra
I have some questions regarding python migration along with djnago migration. I have hosted it on google app engine. I need to migrate python from 2.7 to 3.7 and django 1.11 to next stable verdion.
raghvendra
Need to ask you what steps that I have to take for smooth migration
raghvendra
I also used webapp2 for json api call within application for making api call.
raghvendra
i checked official website for webapp2 but it is not completely migrated to python3 . So what steps that I have to do. Should i use some alternative for making api calls
Abhi
Have anyone worked with confluent kafka, if so is there any internal webhook that they confluent provide ? so that i can connect it with other serverices/app.
Mirco
Need to ask you what steps that I have to take for smooth migration
Check on official docs There's a topic about migration
Rammanoj
I have a app running, and I have some data in it's models. I want to generate sql(i.e dml (data manipulation language) statments ) for the entire data in my models. How to perform it ?
Rammanoj
Generate SQL for ?
I have some data in a project running on a server. I want to remove the present server so, I hosted it on the other server. All the database tables are created ( in the new server). But the data in the old server is not backed up. I want to back up the data in the old server to the new one. So, I am trying to generate a dml statements for the models.
Anonymous
Have anybody used mongodb with Django? If so what was your preferred method to connect your app with the db?
Rammanoj
`DATABASES = { ‘default’: { ‘ENGINE’: ‘djongo’, ‘NAME’: ‘your-db-name’, } }`
Rammanoj
`DATABASES = { ‘default’: { ‘ENGINE’: ‘djongo’, ‘NAME’: ‘your-db-name’, } }`
I guess this works. You can refer this once https://medium.freecodecamp.org/using-django-with-mongodb-by-adding-just-one-line-of-code-c386a298e179
Anonymous
`DATABASES = { ‘default’: { ‘ENGINE’: ‘djongo’, ‘NAME’: ‘your-db-name’, } }`
I mean you guys use library like djongo and using ORM to query or only using pymongo and query using mongo syntax. Which one is more effective?
Rammanoj
I mean you guys use library like djongo and using ORM to query or only using pymongo and query using mongo syntax. Which one is more effective?
I prefer using django orm instead of using the queries of that specific db. Using django ORM definetly affects the performance. But it depends on the queries how much the performance is affected. If the query that you are running is very very complex then it is preferable to run a raw query, else both of them will execute almost in same time. (however I am not completely sure which is preferable). You can refer here https://stackoverflow.com/questions/44329757/django-queryset-vs-raw-sql-performance-considerations. This link is for ORM vs sql
Alexander
how to add fields query arg (https://www.django-rest-framework.org/api-guide/serializers/#example) to swagger.json (I use drf-yasg app)? please, show me your ViewSet mixin
Loki
I have models Printer And Check. I needed to return Printer object with 'api_key' as argument (i.e. 127.0.0.1:8000/printers/112233) with all it's children (in my case it's Check objects). I did it this way https://dpaste.de/vutr. But now I need to go from that Printer object to some of his children (i.e. 127.0.0.1:8000/printers/112233/413 where '413' is child's pk). And I really stuck on that task. Any ideas?
Mirco
First prepare your path to accept that parameter and then use it into your view
Loki
Let's assume I have models Album and Track and there is field album = models.ForeignKey(Album, related_name='tracks', on_delete=models.CASCADE) in Track model. I am getting GET request and have to return Albums with their tracks. It is easy. But is it possible to return all Tracks with the album they belong? Like here https://dpaste.de/FQKr#L32
Mirco
You can use them to avoid hardcoded urls and so typo issues
Anders (izzno / gooood) 🇳🇴
How do you send emails async in Django?
Jimmies San
celery? django-q-mail?
Anders (izzno / gooood) 🇳🇴
celery? django-q-mail?
Oh, I need a third party?
Anders (izzno / gooood) 🇳🇴
Looks easy enough though, thanks.
Anders (izzno / gooood) 🇳🇴
In a glance Q looks faster to get up and running than celery, thoughts?