/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

137,367 Subscribers

0

Wants to make a full stack YouTube like application , here is confusion

so i have made this Youtube like full stack project in React & node

react on frontend and express on backend and yes frontend is alone.

so main confusion is that i wanna built the same in django so should i use django-template with creatng html files and render or just make backend api on django and connect to frontend( as i have already made ).

or should i use react as template and serve through django ( server side rendering)

4 Comments
2024/11/03
06:57 UTC

0

Hello everyone I'm a beginner in django I took help of youtube to start my project of advance finance tracker but I'm lost as there are so many ways could you guys help me out

For my final year main project our group thought of doing django with data science but as I'm not a expert to be frank(I know only basics ) could you guys help me out 🙏 I'll be able to survive my last year

18 Comments
2024/11/03
04:25 UTC

2

Build a Secure Transaction System with Django Rest Framework (DRF) - Step-by-Step Guide

0 Comments
2024/11/02
22:24 UTC

1

One thing about us developers is that we not business people so if you have experience working at a failed startup, what are some signs to look out for to see if you in a sinking ship?

As someone that has worked in a startup that did not do well. I think the signs were there when we client requests were inconsistent. We would serve a client there and there but there was no project that lasted a long time cause usually the service we provided would be complete in a month or 2. The company was funded to build a product so we can transition from providing a service to providing a Saas product but when the investors pulled out that's when it hit the fan that client work revenue was not enough to run a company and we were surviving off funding.

5 Comments
2024/11/02
16:08 UTC

5

DJANGO rest framework with js or DJANGO with jinja template

Hi folks

I have worked on 2 big projects handling big data 

One was using Django templates and the other using DRF with VueJS. 

I found that the majority of people are using DRF with JS frameworks and say that the Jinja template is old.

But I was surprised that some talented developers that do interviews for Django and have built great packages talk about how they prefer the Jinja template. 

So the question is, What do you think about this, and which approach do you use Django with?

20 Comments
2024/11/02
16:01 UTC

48

I discovered context processors

Today I discovered context processors, basically I needed a variable to be globally accessible across all the templates, and wola Django has a built-in and elegant solution.

I love this tool so much!

13 Comments
2024/11/02
14:29 UTC

2

'Authorization' Header Get Stripped on Apache/Ubuntu 24.04

I'm working on a Django app hosted on an Apache server using Ubuntu 24.04.

Even after turning off all middleware, request.headers.get("Authorization") always returns None.

But strangely, changing the header to Authorizationx makes it work. (Notice the 'x" at the end)

Could anyone explain why this is happening with Apache?

Any tips would really help!

7 Comments
2024/11/02
12:03 UTC

13

Projects for open source contributions

I am a junior developer currently and I am interested in contributing to some good, impactful open source projects that are making people's lives easier. I am primarily looking for projects in Python and Django to contribute to.
Can I get some recommended projects, especially in django (or django-rest for that matter). Since I'm a beginner and do not have a rich experience (especially in large-scale projects) I would like to be recommended projects that are not so daunting (like django itself) :)

8 Comments
2024/11/02
05:08 UTC

3

(Unit) Testing without database

tldr how are you writing tests for parts of the code that are requiring ORM?

Hiya,

I am new to Django and looking for guidance in the area of the structuring tests.

Component that I am working now is built on top of Netbox, but with a lot of custom code and features squeezed into plugins.

As the code quality of the plugins is really bad, management came up with the goal of 85% statements coverage (I know, dumb as hell, especially as big chunk of this code is garbage and will be thrown out as soon as it is safe to do). So we have to write a lot of "unit tests" (actually I don't think they need to be unit, they just need to generate coverage).

Okay, so wanted to start with "classic" unit tests, meaning no IO, everything happening in memory. First problem is that almost every method is either querying or saving something to DB. One of the colleagues started mocking every ORM call, like the return values of "Model.objects.filter" etc., which seems off to me (it feels like testing less while demanding more effort to maintain). In previous projects (not Django) I had repositories, which in tests were just replaced with in-memory implementation and it worked fine. However, in current project this does not seem possible, as various models are used all the place (so everything is broken down into apps, but every app imports models from other apps, accesses and modifies any record at any time, which seems like huge headache, but that's another topic).

I thought of using sqlite in-memory, but models are heavily tied to postgres (using JSON fields A LOT) and couldn't make that work. Currently I am tinkering with testcontainers, trying to make postgres as fast as possible, keeping everything in memory etc., and it seems promissing, but those aren't "unit tests" per se anymore. I guess it would be a decent compromise (after refactoring in the hopefully near future) to group code into ORM-independent and -dependent parts, unit test everything that doesn't need to touch DB and test the rest with actual database, but have any of you done this in a project?

Taking a look at the tests of the core Netbox itself, those just demand DB to be there and that's it. Is this a common practice for Django projects, that you don't have "unit tests" (no IO) and "integration tests" (with IO/dependencies), just setup the app with all the dependencies and run tests that way?

12 Comments
2024/11/01
20:03 UTC

1

Having trouble executing query via Solr UI for my Django project

So every time I try to execute a query in the Solr UI, I get blank (0) documents returned. Which doesn't make any sense, considering I have 4 documents that are indexed. I asked this same question about a week ago, and someone on here suggested that I set the required logging levels to 'Trace', which I did do in log4j2.xml.

I also set up search_indexes.py for the indexed fields, created the txt files for each indexed, created a Solr core ( I only have one core), configured indexed fields in schema.xml, rebuilt the index with the following command `python manage.py rebuild_index` with this output ```DATABASE_NAME: arbordb

DATABASE_USER: postgres

DATABASE_PASSWORD: arborcor87

DATABASE_HOST: localhost

DATABASE_PORT: 5432

WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.

Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.

Are you sure you wish to continue? [y/N] y

Removing all documents from your index because you said so.

C:\Users\corey james\AppData\Local\Programs\Python\Python312\Lib\site-packages\haystack\backends\simple_backend.py:30: UserWarning: clear is not implemented in this backend

warn("clear is not implemented in this backend")

All documents removed.

Indexing 4 ArboristReviews records

Indexing 4 arborist reviews

C:\Users\corey james\AppData\Local\Programs\Python\Python312\Lib\site-packages\haystack\backends\simple_backend.py:24: UserWarning: update is not implemented in this backend

warn("update is not implemented in this backend")

Indexing 4 ServicesType records

Indexing 4 services types

Indexing 4 Arborist records

Indexing 4 arborist companys

```

I created some data points for my models via Django Admin, so there is indexed data to be queried. Anyway here is search_indexes.py ```

from haystack import indexes
from .models import ArboristCompany, ArboristReview, ServicesType


class ArboristCompanyIndex(indexes.SearchIndex, indexes.Indexable): 
    text = indexes.EdgeNgramField(document=True, use_template=True)
    company_name = indexes.CharField(model_attr='company_name')
    company_city = indexes.CharField(model_attr='company_city')
    company_state = indexes.CharField(model_attr='company_state')
    company_price = indexes.IntegerField(model_attr='company_price', null=True)
    experience = indexes.CharField(model_attr='experience')

    def get_model(self):
        return ArboristCompany

    def index_queryset(self, using=None):
        qs = self.get_model().objects.all()  # Get the queryset
        print(f'Indexing {qs.count()} Arborist records')  # Print the count of records
        return qs


class ArboristReviewIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.EdgeNgramField(document=True, use_template=True)
    one_star = indexes.IntegerField(model_attr='one_star', default=0, null=True)  # corrected
    two_stars = indexes.IntegerField(model_attr='two_stars', default=0, null=True)  # corrected
    three_stars = indexes.IntegerField(model_attr='three_stars', default=0, null=True)  # corrected
    four_stars = indexes.IntegerField(model_attr='four_stars', default=0, null=True)  # corrected
    five_stars = indexes.IntegerField(model_attr='five_stars', default=0, null=True)  # corrected
    review_by_homeowner = indexes.CharField(model_attr='reviews_by_homeowner')

    def get_model(self):
        return ArboristReview

    def index_queryset(self, using=None):
        qs = self.get_model().objects.all()  # Get the queryset
        print(f'Indexing {qs.count()} ArboristReviews records')  # Print the count of records
        return qs

class ServicesTypeIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.EdgeNgramField(document=True, use_template=True)
    tree_pruning = indexes.CharField(model_attr='tree_pruning')
    tree_removal = indexes.CharField(model_attr='tree_removal')
    tree_planting = indexes.CharField(model_attr='tree_planting')
    pesticide_applications = indexes.CharField(model_attr='pesticide_applications')
    soil_management = indexes.CharField(model_attr='soil_management')
    tree_protection = indexes.CharField(model_attr='tree_protection')
    tree_risk_management = indexes.CharField(model_attr='tree_risk_management')
    tree_biology = indexes.CharField(model_attr='tree_biology')

    def get_model(self):
        return ServicesType

    def index_queryset(self, using=None):
        qs = self.get_model().objects.all()  # Get the queryset
        print(f'Indexing {qs.count()} ServicesType records')  # Print the count of records
        return qs```

One of my txt files, company_text.txt, ```

{{ object.company_name }}
{{ object.company_city }}
{{ object.company_state }}
{{ object.company_price }}
{{ object.experience }}
``` schema.xml ```

<field name="text" type="edge_ngram" indexed="true" stored="true" multiValued="false" />
<field name="company_name" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="company_city" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="company_state" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="company_price" type="long" indexed="true" stored="true" multiValued="false" />
<field name="experience" type="long" indexed="true" stored="true" multiValued="false" />
<field name="one_star" type="long" indexed="true" stored="true" multiValued="false" />
<field name="two_stars" type="long" indexed="true" stored="true" multiValued="false" />
<field name="three_stars" type="long" indexed="true" stored="true" multiValued="false" />
<field name="four_stars" type="long" indexed="true" stored="true" multiValued="false" />
<field name="five_stars" type="long" indexed="true" stored="true" multiValued="false" />
<field name="review_by_homeowner" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="tree_pruning" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="tree_removal" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="tree_planting" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="pesticide_applications" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="soil_management" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="tree_protection" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="tree_risk_management" type="text_en" indexed="true" stored="true" multiValued="false" />
<field name="tree_biology" type="text_en" indexed="true" stored="true" multiValued="false" />
```. Finally are the screenshots of both my Django Admin and Solr UI.

https://preview.redd.it/jgqrfgeoacyd1.png?width=1920&format=png&auto=webp&s=85c5f937909f69a4c24f4bed3752d4f5c6c07e75

https://preview.redd.it/7k8l473zacyd1.png?width=1920&format=png&auto=webp&s=20110d78f55aa7a9165ce480df60a86638e793fc

https://preview.redd.it/2glt95t1bcyd1.png?width=1920&format=png&auto=webp&s=613d0662098843e9685a33da7e1da28546f9487a

Any suggestion would be great. For reference, when I click on the search tool bar for my search engine page, it does show some of the arborist company names via autocomplete. Just can't seem to figure out why more documents aren't return when I run the query. If you need anything else from me, please let me know. Thank you.

0 Comments
2024/11/01
19:18 UTC

12

Tell one hard truth to provoke a "lazy" Jnr. dev to be serious.

As an experienced developer, what hard truths do you have tell a Jnr Dev to wake up from his slumber and be serious and thrive in this software development industry.

41 Comments
2024/11/01
17:56 UTC

3

Practice with system design interview book

Hi everyone,

I'm currently reading System Design Interview by Alex Xu. A lot of the concepts, such as setting up a server with a load balancer, implementing a rate limiter, using a consistent hash ring, and others, are new to me. I'm wondering if there are any resources, like a GitHub repository, where I could practice these concepts with step-by-step instructions.

Any recommendations?

0 Comments
2024/11/01
15:44 UTC

36

Feature Friday: LoginRequiredMiddleware!

The LoginRequiredMiddleware (new in Django 5.1) is great for any Django app that is mostly behind authentication. When enabled, views will require login by default. No more login_required decorators everywhere!

So how do you make a view not require login?

Use the new login_not_required decorator! This works just like the login_required decorator but for the opposite: any view it decorates will bypass the login requirement and be public. Be sure to put it on your login page otherwise you might get caught in redirect loops!

If you're building an app that mostly requires login, using the LoginRequiredMiddleware is a great way to simplify code and prevent accidentally leaking content—by making your app private by default.

Read more in the documentation here: https://docs.djangoproject.com/en/5.1/ref/middleware/#django.contrib.auth.middleware.LoginRequiredMiddleware

4 Comments
2024/11/01
13:11 UTC

1

Identifying same images by giving hash values in django using celery and redis

How can i do this? My goal is to take two images and the images should be assigned hash values,based on the image names

If two pics got same hashvalue,they will have same hash values and only one will be saved by redis

11 Comments
2024/11/01
11:14 UTC

7

Login for different Users

Hi I'm new to django. I'm currently doing a project Event management like a wedding, corporate conference, or community festival, involves coordinating various elements, such as budgets, vendors, guest lists, and schedules. I'm using django rest framework and React vite. So to start i want different login for planners , vendors , guests , admin. So should I create a single model for storing all the user credentials ? How to differentiate various user types like for planners they can view edit and book events , and for guests only viewing etc .

17 Comments
2024/11/01
09:39 UTC

12

iommi 7.7.0 released

News:

  • Upgraded default Bootstrap version that now includes automatic dark mode
  • New crud_views() function added. Create an entire CRUD for a model in a single line (more on that here: https://kodare.net/2024/10/15/implementing-neapolitan-in-iommi.html)
  • iommi now ships with some views that you probably need: login, logout, change_password
  • Added CSS Frameworks: Vanilla CSS, US Web Design System
  • Form.create_or_edit() added
  • EditTable now supports 1-to-1 fields
  • Significant performance improvemnets
  • Many bug fixes and smaller features

https://docs.iommi.rocks/

https://github.com/iommirocks/iommi

3 Comments
2024/11/01
09:11 UTC

2

LSP server in django

Hello, I want to create a LSP server in django, that could communicate with monaco code editor in javascript at front end. I've done some googling but unable to get directions. If anyone can guide me in correct directions, that would be great.

I'm experienced developer but relatively new in django. Thanks

3 Comments
2024/11/01
07:04 UTC

1

Seeking Guidance: Deploying Django App on Coolify - Best Practices and Step-by-Step Guide

Hi fellow Redditors,

I'm a beginner seeking help deploying my Django web application on Coolify. Here's my setup:

  • Django web app with MySQL database
  • Developed locally using Apache XAMPP
  • Migrated and running smoothly on localhost
  • Code is ready in a folder (not on Git)

I've met Coolify's minimum requirements and successfully deployed a test Next.js application. However, when I try to access the deployed domain, it doesn't load.I'm looking for guidance on:

  1. Preparing my Django project for Coolify deployment
  2. Configuring database settings (MySQL) on Coolify
  3. Handling static and media files
  4. Environment variables and settings
  5. Troubleshooting common deployment issues

Specific questions:

  • Do I need to modify my Django (link unavailable) file for Coolify?
  • How do I connect my MySQL database to Coolify?
  • Are there any specific requirements for (link unavailable) or requirements.txt?

Any step-by-step guides, tutorials, or advice from experienced users would be greatly appreciated!

Thanks in advance for your help!

4 Comments
2024/11/01
06:43 UTC

1

Need help in a project deployment not sure how to do so no clear lectures to help

Hi everyone, I'm a intermediate programmer trying to deploy my Django project. I've been following tutorials and documentation, but I'm still running into issues. Specific Problems I'm Facing:

  • Heroku:
    • Configuring the Procfile
    • Setting up the requirements.txt file
    • Deploying static files
    • Connecting to a database (Heroku Postgres)
  • PythonAnywhere:
    • Creating a virtual environment
    • Configuring the WSGI file
    • Deploying static files

I've tried troubleshooting by checking logs, adjusting settings, and following online guides, but I'm still stuck. Any advice or tips would be greatly appreciated. I'm open to using other platforms or services if they might be easier. Thanks in advance for your help!

0 Comments
2024/11/01
06:07 UTC

0

run local server without manage.py ?

How to run local server without using manage.py file ? Like do it manually through my new file !

12 Comments
2024/11/01
03:08 UTC

7

For those who DON'T charge hourly, How much do you charge for your services?

I've just graduated from my software engineering course and I'm already getting a few clients, but I'm trying to figure out what the standard rate is for my services. I don't charge hourly, but rather have a set price for the entire project.

How much do you guys charge for:

  • Business Website
  • E-Commerce site

and anything else that you've built?

6 Comments
2024/10/31
22:19 UTC

29

I need a job

I am a backend developer with 1.5 years of experience in Python, Django, flask, FastAPI, Rust, PostgreSQL, MySQL. I’m in Ghana, West Africa but I can work remotely anywhere. I can work within any time frame or difference. I really need job 🙏🏾 This’s my GitHub: https://github.com/miky-rola

18 Comments
2024/10/31
20:08 UTC

3

How to structure a django project with celery?

I'm currently working on a content aggregator project for practice purposes and for the exact reason I've chosen to use django with celery and redis as a message broker. A simple API written in django and DRF is the only experience I've had so far.

The problem is that I just can't start writing code because I don't know where to start. I can't figure out how the structure of the project should look like.

The idea is simple: django displays the content scraped by celery workers from various websites. There is no need for storing the data so they will wait in the redis memory until the moment to be displayed comes.

I've read celery docs and have a general idea about how it's done with the task decorators and delay functions but is it really practical to use them that way? I've searched through some open source projects that supposedly use celery and there were none of these delay functions and task decorators.

I guess I just want to ask how to bundle it all together?

2 Comments
2024/10/31
19:04 UTC

18

Django 2 hour interview

I have a 2 hour django coding round. What are some examples of what could be asked for this given its two hours and this is specifically a backend role? Has anyone had experience with interviews like this?

10 Comments
2024/10/31
17:23 UTC

6

Step-by-Step or Selectively?

I’m a beginner learning Django and want to develop a web app. I found a course online that consists of 12 videos. I’m wondering what the best approach is: should I follow the course step by step, or can I skip ahead to the videos that cover what I want to implement? So far, I've completed the home and about pages from video 1, but I'm eager to implement the sign-up and login system, which is covered in video 9. Would it be better to watch the entire course for a solid foundation, or is it okay to jump to the specific videos I need?

6 Comments
2024/10/31
15:27 UTC

5

Learning method

currently im reading "django 5 by example".The way i learn is by reading and typing and running the code in my pc page by page.

Is this good for me? Is my learning way efficient?if not what steps and measures should i take?

6 Comments
2024/10/31
15:23 UTC

1

SSO inter-domaine

J'aimerais créer un serveur web qui gère les connexions pour tous mes autres sites. Voici le principe de ce que je souhaite réaliser :

Lorsqu'un utilisateur clique sur "Login", il doit être redirigé vers le serveur web où il peut se connecter avec Discord. Après cette connexion, il sera automatiquement redirigé vers le site d'où il venait, et il sera également connecté sur tous mes autres sites.

si vous avez pas bien compris foici un exemple:
https://but-info.septhime.fr/ je veux faire exatement son system spthime connect

Est-ce que je peux réaliser cela avec Django ? Si oui, avez-vous des documents ou des ressources qui pourraient m'aider à mettre en œuvre ce que je viens de décrire ?

0 Comments
2024/10/31
15:11 UTC

Back To Top