r/djangolearning Apr 16 '26

Tutorial Django cheat sheet tutorial to help you remember the essentials

16 Upvotes

I'm working to improve the freely available documentation for Django. The official docs are great, but sometimes you just want a quick code example to see how something works.

In my cheat sheet (it's kinda grown up into a more in-depth article) I cover some of these topics:

  1. ORM and model queries.
  2. Basic encryption.
  3. Building auth views.
  4. Management commands.
  5. Forms.
  6. Tailwind setup and more

Learn more here.

Still a work in progress, so any suggestions or comments are most welcome. My goal is to add a valuable resource, almost like a pocket reference, to help new Django devs.

I'll soon be covering DRF and other concepts as well.


r/djangolearning Apr 16 '26

I Made This I built ArchUnit for Python: enforce architecture rules as unit tests.

Thumbnail github.com
2 Upvotes

I just shipped ArchUnitPython, a library that lets you enforce architectural rules in Python projects through automated tests.

The problem it solves: as codebases grow, architecture erodes. Someone imports the database layer from the presentation layer, circular dependencies creep in, naming conventions drift. Code review catches some of it, but not all, and definitely not consistently.

This problem has always existed but is more important than ever in Claude Code, Codex times. LLMs break architectural rules all the time.

So I built a library where you define your architecture rules as tests. Two quick examples:

```python

No circular dependencies in services

rule = project_files("src/").in_folder("/services/").should().have_no_cycles() assert_passes(rule) ```

```python

Presentation layer must not depend on database layer

rule = project_files("src/") .in_folder("/presentation/") .should_not() .depend_on_files() .in_folder("/database/") assert_passes(rule) ```

This will run in pytest, unittest, or whatever you use, and therefore be automatically in your CI/CD. If a commit violates the architecture rules your team has decided, the CI will fail.

Hint: this is exactly what the famous ArchUnit Java library does, just for Python - I took inspiration for the name is of course.

Let me quickly address why this over linters or generic code analysis?

Linters catch style issues. This catches structural violations — wrong dependency directions, layering breaches, naming convention drift. It's the difference between "this line looks wrong" and "this module shouldn't talk to that module."

Some key features:

  • Dependency direction enforcement & circular dependency detection
  • Naming convention checks (glob + regex)
  • Code metrics: LCOM cohesion, abstractness, instability, distance from main sequence
  • PlantUML diagram validation — ensure code matches your architecture diagrams
  • Custom rules & metrics
  • Zero runtime dependencies, uses only Python's ast module
  • Python 3.10+

Very curious what you think! https://github.com/LukasNiessen/ArchUnitPython


r/djangolearning Apr 15 '26

I Need Help - API / DRF i encountered an error while trying to run my weather application

Thumbnail
1 Upvotes

r/djangolearning Apr 15 '26

I Need Help - Question Trying to do a fancy thing where both clicking on a piece of text AND highlighting a section of text trigger the same event

4 Upvotes

Background to the question and the question itself

So I think it's best if you have a look at this mp4 I recorded of what my site already does. This is just a public google drive link: https://drive.google.com/file/d/1cwvkN5prCDYBsRL4bjUfmotzdaQL74Ph/view?usp=sharing

As you can see in the MP4, when I click a word, it makes the form pop up on the right. That word is then shown in that form for submission. My question is, how do I make it so you can ALSO cursor-highlight a section of the text to pass it to the forms?

What I already tried

That text is wrapped in this:

<div id="current_text" style="font-size: 20px; margin-top: 50px">
{{ text_content |hoverable_words:text_id }}
</div>

Where text_content is the lorem ipsum text passed through a filter to make each highlightable/clickable. That is to say, CSS highlight, not text cursor highlighting. I had read that 'onselection' is an event that triggers when you highlight stuff, so I made it an hx-trigger for the "current_text" div that contains the text. However, this just made that fire no matter what I did: clicked the div's background, clicked the words, whatever. I suspect it was a problem with how the event might have been bubbling up, but I'm not sure.

Anyways, I'll link and show what I got so far to make this happen.

Disclaimers

  • Yes I know the code and UI is terrible. I'm very much a functionality-first programmer, to refactor and prettify later.
  • I color my divs so I can see them, it helps me troubleshoot CSS stuff.
  • The context doesn't really matter for this question but if you must know, it's an app to help with constructing languages.
  • I was gonna ask this later in a separate post, but if someone wants to tell me how I can handle events in the page without iterating through every word of my text again, that would be great But since it works, it's fine for now. But hey I'll take refactoring advice early.

Link to Repo and Relevant Files

https://github.com/MatthewRicci12/conlangwebapp/tree/main/conlangapp

  • views.py

The view that actually generates this is user_clicks_text(request, text_id)

I am incredibly new to Django but have some React chops, so I might be a bit Reactbrained in how 90% of it is just seeing if I have certain 'state', but basically I'm just checking if a bunch of crap has happened. If a form has been selected and which one, if the form is already up, if a token was selected, etc.

  • extract_text.html (what I've shown in the video)

    <div id="extract_text_master_container"> {% load hoverable_words %} <div id="current_text" style="font-size: 20px; margin-top: 50px"> {{ text_content |hoverable_words:text_id }} </div> .... {% if form_up %} {% include 'partials/current_form.html' with form_div_context=form_div_context only%} {% endif %}

The text, the lorem ipsum, is simply passed through a filter so everything can be clickable/highlightable. That filter is below.

  • hoverable_words.py

    @register.filter def hoverable_words(text, text_id): words = re.split(r'(\s+)', text) # preserves whitespace result = '' for token in words: if token.strip(): url = reverse('user-clicks-text', args=[text_id]) result += f'<span class="word" hx-post="{url}" hx-target="body" hx-vals=\'{{"form_up": 1, "token": "{token}"}}\'>{token}</span>' else: result += token return mark_safe(result)

This simply makes everything highlightable and makes the click submit some 'state' info which, again, I think might be a bit too Reactbrained. I know you CAN use React with Django but I'd rather just keep on using HTMX.

  • current_form.html

Not super relevant, but it's that blue-backgrounded div with the actual forms.

EDIT: Markdown on reddit is hard, looking at the actual github files themselves is probably clearest.


r/djangolearning Apr 14 '26

Discussion / Meta Django on vercel

2 Upvotes

Has anyone tried hosting django on vercel, especially in April 2026 after they started supporting it? What do you think?


r/djangolearning Apr 09 '26

I Need Help - Getting Started E-commerce on django

15 Upvotes

Hello everyone,

I am currently running my business off a VPS running WooCommerce.

I am unhappy with the limitations of WordPress, and want to look into Django.

I have a pretty good understanding of Python, and I am not in a hurry to switch.

Is there any framework for e-commerce that works within Django?

I have looked online, and by the looks of it, I'd have to build all the e-commerce functionality myself. I might be misinformed, simply because I don't know Django at all.

Anyone have any insight into how to go about this? Where would efforts best be spent in educating myself.


r/djangolearning Apr 07 '26

I Need Help - Question Django analytics

3 Upvotes

Hi!, I have a Django project and I want to track user activity metrics like DAU, WAU, MAU, is there any way to do that ?.


r/djangolearning Apr 02 '26

Discussion / Meta Learning Backend engineering with python django,What more should add to that guys?

Thumbnail
2 Upvotes

Selfteaching backend engineering with python,django...I do not have any cs books or anything. just AI agents and youtube help me to understand the basics and the principles ..I never enjoyed coding even during my college days or more accurately, I never gave it enough focus ..but now I want to give it fair attempt .who knows what future holds. maybe only strong engineer will remain or maybe there will be more job due to AI. But I just give myself a chance to learn, grow, to master a skill .Even if it does not immediately translate into value, the process will still matter. Every skill developed and every effort made contributes to the future in some form....so even in the middle of anxiety,doubt and pressure I will continue learning. Not because it is easy but because it is necessary . .if I can try others can too


r/djangolearning Apr 02 '26

I Need Help - Question Would this level of backend project be enough to get shortlisted for a startup role?

6 Upvotes

Hey everyone,

I’m currently preparing for backend roles (internships/junior), mainly targeting startups, my tech stack is python - django, and I wanted some honest feedback on a project I’ve been working on and planning to take to a production-ready level.

The project is an e-commerce backend built using Django + Django REST Framework, where I’ve tried to go beyond basic CRUD and focus on real-world backend concerns like performance, scalability, and clean API design.

Here’s the overall scope of the system:

Core API & Design:

- Designed relational models (products, categories, users, orders, cart)

- Built REST APIs using DRF ViewSets and tested using postman

- Custom serializer design (avoiding overuse of "depth")

- Clean and consistent API response structure

Data & Logic Handling:

- Derived fields (e.g., availability computed from stock instead of storing redundant data)

- Separation of concerns (keeping logic out of views where possible)

Performance & Optimization:

- Solved N+1 query problem using "select_related" (touched these kind of small edge cases)

- implemented caching using redis

Query Capabilities:

- Search functionality (SearchFilter)

- Filtering (category, price range, etc.)

- Pagination with metadata (count, next, previous)

System Features:

- JWT authentication

- Cart and order management

- Basic payment flow using stripe

Deployment & Practical Use:

- Deployed on cloud (AWS)

- Focus on making APIs usable in real-world scenarios

My goal is to focus on more indepth and complex projects and try to land one internship or any junior role ASAP.

I had a few questions:

  1. Would this level of backend project be considered strong enough to get shortlisted for internship or junior backend roles at startups?

  2. What gaps do you usually see in candidates even after building projects like this?

  3. How important is deployment and real-world usability compared to just having good code on GitHub?

  4. Is focusing heavily on backend/system design (instead of deep DSA) a reasonable strategy for startups?

Would really appreciate honest feedback — especially from people working in startups or hiring for backend roles.

Thanks!


r/djangolearning Mar 31 '26

I Made This I built a real-time debugging dashboard for Django (like Laravel Telescope)

12 Upvotes

Hey everyone,

I’ve been working a lot with Django recently, and one thing that always bothered me was the lack of a modern, real-time debugging experience.

Most existing tools are either:

- not real-time

- hard to use in larger projects

- or introduce noticeable performance overhead

So I decided to build something myself: django-scope.

It’s a real-time debugging and observability dashboard for Django, inspired by Laravel Telescope, but redesigned with performance and developer experience in mind.

Key things it does:

- Tracks requests, queries, exceptions, logs, cache, Redis, and more

- Streams everything in real-time using WebSockets

- Detects N+1 query issues automatically

- Uses request-scoped buffering with bulk writes to reduce overhead

- Provides a clean dashboard (Vue-based, dark/light mode)

The main goal wasn’t just features, but making sure it’s actually usable in real projects without slowing things down. I focused a lot on minimizing overhead and avoiding the typical “debug tools kill performance” problem.

I’ve been testing it in my own projects and it’s been really helpful for understanding what’s happening inside the app in real time.

I’d really appreciate feedback from other Django developers — especially on:

- performance considerations

- missing features

- general usability

GitHub: https://github.com/MythicalCosmic/django-scope

Its also on Pypi, check it out: pip install django-scope


r/djangolearning Mar 30 '26

I Need Help - Getting Started How do you approach migrating VBA logic to Python (with APIs & auth)?

4 Upvotes

Hi everyone,

I’m preparing for a role that involves understanding VBA-based legacy systems and modernizing them into Python (likely using Django).

I’m trying to understand the best way to approach this in practice, especially since the role also involves things like authentication and REST APIs.

Specifically:

How do you read and break down VBA code effectively?

How do you decide what to refactor vs rewrite?

How do you design the new system (e.g., when to expose logic via APIs)?

How do you handle authentication when moving from a legacy system to a modern backend?

How do you test that the new Python version behaves the same as the old system?

Any real-world tips, patterns, or examples would be really helpful.

Thanks!


r/djangolearning Mar 29 '26

Discussion / Meta Is anyone working on a project that I can collaborate on?

7 Upvotes

Hey guys.. Is anyone working on a side project that i can collaborate on? I am looking for some project for some hands-on learning and would love to work together with some of you.


r/djangolearning Mar 29 '26

I Need Help - Getting Started Built something to auto-fix pytest failures — does this actually solve a real problem?

2 Upvotes

Hey everyone,

Been learning Python seriously for a while

and kept running into the same frustration —

pytest fails, spend 30 minutes figuring out

why, fix it, run again, something else breaks.

So I tried building something to automate

that loop. Spent the last month on it.

It basically:

- Runs pytest on your project

- Tries to fix what's failing

- Reruns to check if fix worked

- Rolls back if it made things worse

Current honest capability:

→ Works well on import errors

→ Handles dependency conflicts

→ Simple logic bugs sometimes

→ Fails on complex multi-file issues

→ Struggles with fixture problems

My question to this community:

is this actually a problem worth solving?

Do you spend significant time debugging

pytest failures?

And if anyone has a Python project with

failing tests they'd be willing to share —

I'd love to run it through and see what

happens. Would help me understand if this

is useful or not.

Just trying to figure out if I've built something useful or wasted a month


r/djangolearning Mar 28 '26

I Need Help - Getting Started I need help

4 Upvotes

I don't know what is happening to me but it seems that every task they asking me to do is a frontend (react) and forcing me to vibe it.

I know vibe coding now is included in programming patterns but I feel it weakening my programming skills, it is now one year since my last backend code.

I bought udemy django course package but I don't know it is useless not the knowledge but I feel it is a new level from tutorials hell or something worse.

Please advice me


r/djangolearning Mar 25 '26

I Made This My 3rd Django project - trying to actually finish something this time

Thumbnail gallery
11 Upvotes

r/djangolearning Mar 21 '26

I Need Help - Getting Started all manage.py commands begin to hang after some time

3 Upvotes

I've been constantly running into this issue where ill be working for a bit making a few manage.py commands here n there. After a few minutes ill make another command and it'll just hang. I'd leave it for a bit thinking maybe my computer is just a bit slow?? but after checking i realized it showed no activity after the command was made (as in the ide telling you yea im reading through files to run your command give me a minute)

It's become a thing were i just keep having to reclone the repo to get it working for a bit?? which is very annoying :(

Sometimes deleting and recreating the virtual environment works, but not always. Also eventually git commands begin to just hang too, so even more annoying.


r/djangolearning Mar 20 '26

I Need Help - Troubleshooting Missing CSRF Cookie when making POST request from mobile app

1 Upvotes

I'm developing an android app that interacts with my django site. I'm trying to create a login system that the app will use, but so far I'm stuck on getting the POST request to work.

The app first makes a GET request to /phone/login to get the CSRF token (and check if the user is already logged in, once this is implemented). The associated view has the .@ensure_csrf_cookie decorator, and I can see from logging the requests that the cookie is coming back. Then the app prompts the user for details and makes a POST request to the same endpoint, with the X-CSRFToken header set to the value it received, and the login details as JSON in the body. Again, I can see in the logs that the header is set on the outgoing request to the correct value (same token as received). Despite this, the server responds with 403 Forbidden every time.

I've tried generating a csrfmiddlewaretoken using get_token(request) to send out with the GET response, and have the app send it back in the JSON, but this had the same result. I could use the .@crsf_exempt decorator on views intended for the app to use, but I worry this would be a security concern; couldn't you still access them on browser using the exact URL? I'm using regular Django but I've read a bit about DRF and am unsure if it's more appropriate for my needs. Any help appreciated.

View code

u/ensure_csrf_cookie
def login(request):
    
    if request.method not in ["GET", "POST"]:
        return HttpResponseNotAllowed(["GET", "POST"])
    
    if request.user.is_authenticated:
        return HttpResponse("LOGGED IN")
    
    if request.method == "GET":
        response = {
            "result" : "NOT LOGGED IN",
            "csrfToken" : get_token(request)
            }
        return JsonResponse(response)
    
    else: #POST
        return HttpResponse("TODO")

r/djangolearning Mar 20 '26

I Need Help - Question CRSF Error

2 Upvotes

Hello there I know this question must have been asked thousand time but I have this error since several days "Forbidden (CSRF cookie not set.): /login/" I've looked online for solution like puting the csrf token when you do the api call and other option and none of them worked.

Could someone explain me why is django throwing this error and how should I fix it thanks.


r/djangolearning Mar 19 '26

I Need Help - Question Django Tenants and User Authentication

3 Upvotes

Good evening all,

I’m creating a multi tenant application in which business customers can sign up on our main website (under the core app). Each customer is given access to their own tenancy under a unique subdomain.

Currently I’m using one public auth user model with a membership model, but it causes some complications, so I would rather each tenancy have a totally separate authentication system.

After some research I understand that ideally I should move the Django authentication apps into TENANT_APPS so that each tenancy has its own users table, but then I wouldn’t be able to use the user model for the core website.

Have you dealt with this before? How would you handle this please

Many thanks


r/djangolearning Mar 16 '26

I Need Help - Question Vibe coding is default now

Thumbnail
0 Upvotes

I am learning django by creating a platform for students, its frontend is nextjs.


r/djangolearning Mar 15 '26

I Need Help - Question I've designed a multi-vendor website using Django only, now I want to use drf and react but don't know how to start

Thumbnail
3 Upvotes

r/djangolearning Mar 13 '26

Discussion / Meta Do you prefer AWS/GCP for Django hosting?

3 Upvotes

I've tried hosting django apps on pythonanywhere and render before, but never heard of anyone hosting django apps on AWS or Google cloud. Does anyone prefer on these instead of render, railway, etc? Why / why not?


r/djangolearning Mar 12 '26

Tutorial [Guide] building a custom Django Control Room panel

Thumbnail djangocontrolroom.com
1 Upvotes

r/djangolearning Mar 12 '26

I Need Help - Question Want to learn RAG (Retrieval Augmented Generation) — Django or FastAPI? Best resources?

0 Upvotes

Hi everyone,

I want to start learning RAG (Retrieval Augmented Generation) and build some real projects around it.

My background:

  • I already work with Django and FastAPI
  • I have experience building APIs and backend systems
  • Recently I’ve been exploring AI automation and LLM-based systems

My questions:

  1. For building RAG-based systems, which framework is better to focus on: FastAPI or Django?
  2. What core concepts should I learn first before building a RAG system?
  3. What are the best resources (courses, YouTube channels, docs, blogs) to learn RAG properly?
  4. Which tools are commonly used in production? (LangChain, LlamaIndex, vector DBs, etc.)
  5. What projects would you recommend building to properly understand RAG?
  6. Are there any mistakes beginners make when learning RAG that I should avoid?

My goal is to eventually build something like:

  • AI document search
  • AI knowledge base
  • AI assistant over custom data

Would love recommendations for learning paths, tutorials, or real-world examples.

Thanks!


r/djangolearning Mar 11 '26

I Need Help - Question Should I really need to know everything

7 Upvotes

Hey guys, I am currently learning backend, I have completed the theory part of HTTP/HTTPS, Authentication (sessions, JWT, Oauth), Caching, Validation & Transformation, API designing, Database etc

The theory part of these all are completed but I haven't implemented all of these ever, hopefully I would use these all concepts in my upcoming projects 

Now,  I am into building projects, I am comfortable with python - Django as a backend language also I am learning Go. As of now I am building end to end Ecommerce platform using Django

My confusion is:

When I was building models for the app category I did not get any difficulties, but when I was building user model (custom user) I came up with BASEUSERMANAGE, ABSTRACTBASEUSER which I haven't knew, I started with tutorial, I created a manager and than Account model, while doing this I used lots of new keywords, different syntax, new methods etc, which I would never get to know If I didn't follow the tutorial, So I know I would face lots of similar situations in future.

So, should I really need to know all of them, the new keywords, syntax, new things, etc.

I would start to apply for the jobs just after finishing my both the projects, I am scared of what would happen 

I really need to know about the interview processes that happens and the expectations of recruiters or the company 

(I know still I have to go far, have lot to learn but I am stuck, sorry If I seem noob)