/r/django
News and links for Django developers.
News and links for Django developers.
New to Django? Check out the /r/djangolearning subreddit.
Django's Code of Conduct applies here, so be good to each other.
/r/django
Get a 1-Year Perplexity Pro Voucher for just $29 (regular price $200) through my service provider.
This includes access to advanced models like:
Works globally and payments are accepted via PayPal for buyer protection.
Vouch from Buyers, Feedback 2, Feedback 3, Feedback 4, Feedback 5
which one should I go with guyz
I’m currently looking into integrating the new OpenAI realtime API into my Django project. The issue is it seems to need ASGI to facilitate an open live connection.
I’ve looked at LiveKit to help integrate the new OpenAI realtime API too, which relies on web sockets.
Has anyone successfully implemented this in a Django project yet? I’m trying to figure out the most straightforward way of doing this.
Thanks in advance!
Hi all,
I have a VIP setup on keepalived -> haproxy on prox1 and prox2. From here I have 3 webservers, web1-3.
-django project setup with ldap modules installed
-nginx sees hostname bind from haproxy
-gunicorn setup with the same hostname value in .env for allowed hosts
-hosts file has hostname listed
I have also setup a direct hostname to each webserver, and configured it as an alias in nginx/allowedhosts
Now the problem is I can ldap auth from the direct hostname (lets called it web1.company.com), but not the haproxy hostname - (app.company.com) and I'm not sure why. I can reach app.company.com, load pages, load balance, etc.
Does anyone have any ideas here? I tried doing ldap passthrough in haproxy, but that doesnt seem to be doing anything!
hello everyone! just launched doc2exam on ProductHunt
a place to turn any material into live exams -- for students prepping or professors setting official certifications
upvotes are welcome : http://producthunt.com/posts/doc2exam
big milestone for me personally, but journey continues
powered by django, django-allauth (heavily styled with shadcn), drf
can answer any questions here
I inherited a Django project that runs inside Docker. I’ve managed to get it running, but I have some questions about improving the development experience.
When I write code, I like to test how functions work or behave quickly. In other projects, I simply right-click to run/debug. In Django, I’ve found the following approaches, but each has some friction:
Write a Test and Trigger Debug Inside the Pycharm IDE
This works, but it requires connecting to Docker every time or starting a test container, which feels slow for quick tests.
Write an Endpoint and Trigger it
This also works, but I haven’t found a good way to debug or set breakpoints in my IDE to start debugging there.
Use the Django Python Shell
So far, this has been the best option, but it still involves friction. I need to copy code, import a lot of libs manually, and rely on print statements, which I’m not a fan of.
What do i oversee ? How can i improve my developing experience ?
I am working for an NGO. Their plan is to introduce a referral system. The idea is that when a person (A) refers another person (B) his referral count is increment by one. But when B refers (C) the referral count of both A and B will be incremented by 1
This is a basic dfs problem.
For the members already registered who have no parent node. I am planning on making a master node.This will be the top most node in our structure and its referral count gives us how many members are in our network.
How do i optimize my system? What db to use? (Using postgres right now) How do i store this data structure in our db?
I am a fresher straight out of college with a little bit of knowledge about the web and django.
Currently i have two approaches going on in my mind Approach 1: when a new referral is successful just connect it to the node which referred it in the db (optimal for writes, but when we need the count of any node we'll have to do recursive dfs in order to find the count)
Approach 2: for each node maintain a string of ancestor id's seperated by a special token and referral count too. Whenever a new referral is successful ancestor string from the parent is taken and the id of parent is appended to it and assigned to the child. After wards we vist all the the nodes in the ancestor string of the child and increment their count by 1. (Optimal for reads but writes will take time)
What approach would you suggest is better?
What else am i missing something??
Alright so I created a chat application with Django, basically there are "Hives" which you can join and then chat on a certain topic. I created this app to create a space for university students and alike, who want to collaborate or learn something, and thus they can create or join hives and share resources on a certain topic.
I would really appreciate if you could test my site out by playing around with it a bit :)
Please create an account, it's free (doesn't even require a legit email for now :))) ).
Here's the link:
https://aneeb02.pythonanywhere.com
I have a Django application that functions as an API. Currently, it can generate access and refresh JWT tokens and save these tokens as cookies. My problem arises when verifying these tokens in other endpoints. Even though they are being sent correctly, authentication fails. It would be too much information to explain here, but I customized the user class and configured it to use JWT. I appreciate any help, as I'm not sure what to do. When I try to access an endpoint that requires authentication with a token, I receive the message 'Authentication credentials were not provided' and get a 401 error in the response. I believe it could be an issue with the parent class, maybe a method that wasn't overridden but should have been. Here's the repository of the project, which is a small-scale study/test project: https://github.com/MasterTJ123/servant_rpg_back
Two UI kits released in NOV, are now available as libs:
If someone finds this useful, let me know in the comments.
Ty!
I am looking to understand and hopefully learn something as to how FastAPI ended up gaining so much popularity. Is there a lesson to be learned that other open source projects can implement as well. It’s actually a genuine question that I want to find answers to. Thank you!
I am making a media service and the thing is I need permission management. Like which type of user can do what and permission management like giving out other permissions. Can someone help me point to such opensource project.
I've been using Railway for some time now. I've been pretty spoiled with it because of how easy it was to sync with my git repo. However, they keep changing their infrastructure and my sites break whenever they do that. I don't care about pricing. I just want something that's easy to use. I don't have a lot of server and database knowledge. So I had a hard time with services like AWS and Linode. I was still able to get them working.
If not, does anyone know of a tutorial or something that can help me learn how to manage a server for Django?
Coming from python background, django seemed like the perfect choice.
There was a lot of learning along the way. This was my first ever experience in web dev, coming from a large data science background.
I rebuilt over 4 times, and changed from end 3 times from not having all the foresights such as ssr for seo.
My final stack was nuxt/vue with django and postsql, jwt deployed on a digital ocean droplet.
Any questions I’d love to answer, it’s been quite the journey.
Last year, I developed an Instagram clone as a side project. You can check it out here: https://king143nd.pythonanywhere.com/ I would love to hear your valuable feedback on the project and suggestions for improvements. If you're interested in contributing to this project, please let me know, and I’ll share the GitHub repository link. Looking forward to your insights! Git repo link here: https://github.com/KING143ND/FriendZone
Hi guys, thanks for reading my post.
I'm currently making an Ecommerce website on Django that sells electronic devices for my university project. I chose Django as the primary framework since my teacher heavily emphasizes the interaction with databases.
Some clarification before I get to my question is that there are multiple instances of the same product stored within the database with all different IDs. For example, If there are 5 "Laptop A"s, then all 5 of them must have different IDs. So I've been having a lot of difficulty with the process of adding the products into the cart. Additionally, all products have attribute "Status" that indicates whether it's a new or secondhand product.
Suppose for my cart I currently have 10 instances of Laptop A.
7 of them are New and 3 of them are Secondhand.
class Product(models.Model):
id = models.IntegerField(db_column='ID', primary_key=True)
image = models.CharField(db_column='Image', max_length=255)
name = models.CharField(db_column='Name', max_length=255)
price = models.IntegerField(db_column='Price')
m_date = models.DateField(db_column='M_Date', verbose_name="Manufacture Date")
e_date = models.DateField(db_column='E_Date', verbose_name="Expiry Date")
status = models.CharField(db_column='Status', max_length=255)
b_name = models.ForeignKey(Brand, models.DO_NOTHING, db_column='B_Name', related_name='products')
w_addr = models.ForeignKey('Warehouse', models.DO_NOTHING, db_column='W_Addr')
c = models.ForeignKey(Customer, models.DO_NOTHING, db_column='C_ID', blank=True, null=True)
t = models.ForeignKey('Transaction', models.DO_NOTHING, db_column='T_ID', blank=True, null=True)
class Meta:
managed = False
db_table = 'product'
def __str__(self):
return f"{self.id} - {self.name} - {self.status}"
class Laptop(models.Model):
id = models.OneToOneField('Product', models.DO_NOTHING, db_column='ID', primary_key=True, related_name='laptop')
ram = models.CharField(db_column='RAM', max_length=255)
cpu = models.CharField(db_column='CPU', max_length=255)
graphic_card = models.CharField(db_column='Graphic_Card', max_length=255)
purpose = models.CharField(db_column='Purpose', max_length=255, blank=True, null=True)
class Meta:
managed = False
db_table = 'laptop'
def __str__(self):
return f"{self.id}"
How would I go about designing my cart? Since all 10 instances are stored with different IDs and are treated as different products within the database.
Once again, thank you for reading my post.
What are good choices for production level?
I was wondering if someone could provide some basic instructions or recommend a repository I can use as a reference. I want to keep my code as organized as possible without over-engineering it. My tech stack consists of React with TypeScript and Django Rest Framework (DRF). On the front end, I'm using React Router.
Hi r/django
I'm currently in the process of deciding how to implement background tasks/long running operations in my django backend, and i have a few questions that i was hoping some of you might be able to assist me with.
My django backend is a REST API with additional services (hosted on Azure). Currently these services are used sequentially in some of my views and it's starting to reduce performance.
I have one service for calculating carbon footprint for products (items of production companies) based on certain parametres. This service is tightly coupled with our models and is performing database operations.
The other service is using openai to perform certain analyses of said products, in case some data is missing and things needs to be estimated. This service is not coupled to our models.
I need some guidance on the best practice for handling long running operations. I have implemented background tasks before using 'django-background-tasks' and my own database as task backend, but we had to cut that out, since running both the backend server and 'python manage.py process_tasks' in the same Dockerfile introduced some weird behaviours (we used supervirsor for executing two commands in the end of the Dockerfile). Now we need this functionality again, but probably using Celery and Redis. We are a small startup currently with limited daily traffic, since we haven't launched officially.
My questions are:
Keeping the implementation in place:
Separate services on Azure:
What do you guys recommend?
I couldn't post in the web development sub-editor (not enough karma), so I'll ask this here, is there any particular reason one might use mongodb. I mean a problem where only nosql is the solution.
I have made simple websites in Django in the past, basically containing just some photos and text. I would rate my Python skills a 7/10. I'm planning to start a little home business selling products online and I need a website for it. I know a lot of people use sites like Square or Shoppify to setup an online shop but there are a few reasons I'm contemplating making my own website in Django. I have a marketing/analytics background and would love my hands to be completely open to do all sorts of live experimentations, data collection, AI-powered customizations on the website. For example, when a user steps on the website and logs in, I need to spontaneously customize the pages based on the data I have on them and their previous visits/purchases etc. This obviously requires the website to be dynamic and connected to some databases. As another example, when a customer leaves an order, I need the website to be connected to my other Python programs that for example print out shipping labels for the order, send order confirmation sms to the customer, etc.
My question is: if I invest enough time and energy on this, will I be able to build a fully functional, dynamic website like this with all ecommerce features like shopping carts, check out, etc.? Or do you recommend I go the easy way of Shopify/square? Are there any ecommerce features that these tools offer that I can not implement in Django with reasonable effort? Many thanks.
ever since Heroku stopped offering free hosting for Django apps (RIP the GOAT), we've been left with very few good hosting services with free tiers. What is the current consensus for best free-tier hosting providers right now?
I'm picking Django up after a long time away. I'm struggling with something which i feel is probably really basic, so apologies if you clicked this thread looking for a really tricky puzzle to solve.
my models.
#coaches/models.py
class Coach(models.Model):
club = models.ForeignKey(Club, on_delete=models.CASCADE)
name = models.CharField(max_length=200)
email = models.EmailField(unique=True)
phone = models.CharField(max_length=20)
teams/models.py
class Team(models.Model):
name = models.CharField(max_length=200)
club = models.ForeignKey('clubs.Club', on_delete=models.CASCADE)
coaches = models.ManyToManyField(Coach, related_name='teams')
players = models.ManyToManyField(Player, related_name='teams')
This is the view in code.
def team(request):
"""
present the user with a list of teams to choose from
based on their username appearing in the data.yaml file
"""
context = {}
coach = Coach.objects.get(email=request.session["username"])
print(f"Coach: {coach}")
teams = Team.objects.filter(coaches=coach)
print(f"teams: {teams}")
context["teams"] = teams
return render(request, 'coaches/team.html', context)
I've tried this in code and in the shell. this is the output i get.
Coach: Marcelo Bielse
teams: <QuerySet []>
So i correctly populate the coach, but can't pull back the teams the coach is aligned with. ive checked the admin and the coach is definitely attached to the Team. But I always get the empty query set. I wonder if there isnt some 180 degree issue in my thinking that i should be calling for all teams with the specific coach? Is that the area? What have i missed?
Hey,
Repository url: https://github.com/adinhodovic/django-mixin
I've built a monitoring-mixin for Django-prometheus. A monitoring mixin is a set of Grafana dashboards and Prometheus rules written in Jsonnet. There are several others such as https://github.com/kubernetes-monitoring/kubernetes-mixin so I thought of writing one for Django.
I also have a blog post on this topic: https://hodovi.cc/blog/django-monitoring-with-prometheus-and-grafana/.
There's also dashboard preview images in the repository. Looking for any input to hopefully standardize Grafana dashboards and Prometheus alerts for Django over time!
Maybe useful for some! Thanks for taking a look.
Hi all,
I am working on a simple Django app for monitoring the progress of Snakemake workflows. For context, Snakemake is a workflow manager, largely targeted towards life sciences (bioinformatics, genomics, etc). It is run on the command line and currently lacks a good way to monitor the progress of your workflows (they can run for weeks in some cases).
I have experience building Django webapps and deploying them for myself. However with this, I would like to make the whole webapp a pip installable package such that users can just install via pip and spin up the server. This is extremely important, as in order for this to be a useful tool, the barrier to entry should be very low for users with little technical experience.
I have already worked out how the workflows will communicate with the running Django server. My general idea is this:
Where I have questions is how to handle deployment and migrations:
Appreciate any thoughts on this! Happy to answer any questions that would help clarify.