/r/django

Photograph via snooOG

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

139,078 Subscribers

1

Perplexity Pro 1 Year Vouchers (check reviews)

Get a 1-Year Perplexity Pro Voucher for just $29 (regular price $200) through my service provider.

This includes access to advanced models like:

  • Claude 3.5 Sonnet, Claude 3.5 Haiku (Opus Removed), Grok-2
  • GPT-4o, o1 Mini for Reasoning & Llama 3.1
  • Image generators: Flux.1, DALL-E 3, Playground v3 Stable Diffusion XL

Works globally and payments are accepted via PayPal for buyer protection.

How It Works:

  1. Join the 👉Discord of 230+ Members
  2. Pay via PayPal
  3. Promo link redeemed

Vouch from Buyers,  Feedback 2,  Feedback 3,  Feedback 4,  Feedback 5

0 Comments
2024/12/05
03:30 UTC

0

Django or Flask

which one should I go with guyz

4 Comments
2024/12/04
20:45 UTC

1

Has anyone integrated OpenAI realtime API?

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!

0 Comments
2024/12/04
01:08 UTC

2

Django + ldap + haproxy/keepalived

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!

0 Comments
2024/12/04
13:52 UTC

1

users for my django project (doc2exam - Full Self-Driving for exam prep and certs)

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

https://preview.redd.it/swtdmjbm6u4e1.png?width=1200&format=png&auto=webp&s=c5988e97939f6281bba34523aa7d57c6c3165c9c

0 Comments
2024/12/04
13:48 UTC

7

HELP What Am I Missing in Simplifying Django Development with Docker?

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 ?

11 Comments
2024/12/04
12:33 UTC

1

Need some guidance with developing a network marketing system (kind of)

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??

3 Comments
2024/12/04
10:16 UTC

0

Need users for my Django Project

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

10 Comments
2024/12/04
07:32 UTC

0

How to configure JWT to work with cookies?

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

4 Comments
2024/12/03
23:32 UTC

3

Soft UI and Material Dashboard - BS5, latest versions from Creative-Tim, now available as libraries

Two UI kits released in NOV, are now available as libs:

  1. Soft Dashboard: https://app-generator.dev/docs/products/django-libs/theme-soft-dashboard.html
  2. Material Dashboard: https://app-generator.dev/docs/products/django-libs/theme-material-dashboard.html

If someone finds this useful, let me know in the comments.

Ty!

0 Comments
2024/12/03
23:04 UTC

86

How did FastAPI gain so much traction?

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!

56 Comments
2024/12/03
20:19 UTC

1

Permission Management server

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.

2 Comments
2024/12/03
18:48 UTC

1

Railway alternatives?

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?

15 Comments
2024/12/03
17:51 UTC

24

Made a web platform using django over the last 6 months and loved it!

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.

7 Comments
2024/12/03
16:57 UTC

1

Contributors for my Instagram clone

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

2 Comments
2024/12/03
15:44 UTC

2

Adding multiple instances of the same product into cart

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.

11 Comments
2024/12/03
13:15 UTC

5

Complete Django authentication?

What are good choices for production level?

7 Comments
2024/12/03
12:22 UTC

1

Help to set up auth system using React with TS and DRF

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.

8 Comments
2024/12/03
11:25 UTC

3

Celery background tasks using Redis?

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:

    1. Should i keep the implementation in my django project?
    2. If so - how can i avoid having to start the api server and starting the celery workers in the same Dockerfile? The API is currently it's being built from a single Dockerfile and deployed using terraform.
    3. I could use docker-compose and have a service for my backend, redis and for the celery workers?
  • Separate services on Azure:

    1. Is it a better approach to create separate services on Azure and call them from my api?
    2. If so, how should this be done and what kind of service is fitting?
    3. Is this more scalable or does it just introduce more maintainance?

What do you guys recommend?

5 Comments
2024/12/03
09:36 UTC

0

Django and no-sql and SQL

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.

10 Comments
2024/12/03
06:42 UTC

3

Should I use Django for my business website or use boxed alternatives like Square or Shopify

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.

8 Comments
2024/12/03
03:56 UTC

25

Are there any free hosting services for Django now?

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?

39 Comments
2024/12/03
03:47 UTC

4

problems with a many to many relationship.

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?

6 Comments
2024/12/02
20:29 UTC

3

Django-mixin - A set of Grafana dashboards and Prometheus rules for Django!

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.

0 Comments
2024/12/02
20:17 UTC

8

Best practice for self deployable open source Django project

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:

  1. User starts the server
  2. User starts snakemake workflow, gives server address
  3. As workflow runs user can view progress on browser

Where I have questions is how to handle deployment and migrations:

  1. For the database, I'll use sqlite since thats easy and I don't expect high traffic. I'm not sure how to apply migrations to a project that a user has already installed though.
  2. For deployment, I figured I would make some CLI and the run command would spin up the development server. I think that should be sufficient? I'm not sure if there is anything to worry about this. At most I expect that a university cluster admin may run the server so that multiple users can share the server.

Appreciate any thoughts on this! Happy to answer any questions that would help clarify.

2 Comments
2024/12/02
20:12 UTC

Back To Top