/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
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)
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
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.
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?
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!
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!
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) :)
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?
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.
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.
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.
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?
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
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
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 .
News:
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
Hi fellow Redditors,
I'm a beginner seeking help deploying my Django web application on Coolify. Here's my setup:
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:
Specific questions:
Any step-by-step guides, tutorials, or advice from experienced users would be greatly appreciated!
Thanks in advance for your 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:
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!
How to run local server without using manage.py file ? Like do it manually through my new file !
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:
and anything else that you've built?
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
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?
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?
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?
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?
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 ?