Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
How to manage logs with Django, Gunicorn and NGINX
So you want to run a Django app using NGINX and Gunicorn. Did you notice that all three of these tools have logging options? You can configure Django logging, Gunicorn logging, and NGINX logging. You just want to see what's happening in your Django app so that you can fix … -
Cool! I'm going to use it as a base for the article `Create and Deploy Django Server to the GKE`.
Cool! I'm going to use it as a base for the article `Create and Deploy Django Server to the GKE`.Haha. -
Django News - Django Turns 15 and New Releases! - Jul 24th 2020
News Django's 15th Birthday Somehow we missed this last week, but July 17th, 2005 was the public introduction of Django. Here is co-creator Simon Willison's initial blog post. As well as a 2015 talk on Django origins. simonwillison.net Django 3.1 Release Candidate This is the final chance to try 3.1 features before the release on August 3rd. djangoproject.com Python 3.8.5 and 3.9.0b5 released Python 3.8.5 released as a security hotfix. 3.9.0b5, the last beta before 3.9.0, also available blogspot.com Wagtail 2.9.3 and 2.7.4 released Wagtail 2.9.3 and 2.7.4 were released to prevent an HTML injection through form field. github.com Articles XSS Exploitation in Django Applications Anthony Shaw covers various ways to exploit the Django templating engine in a modern web application. github.io Disable Instrumentation Packages during Tests by Adam Johnson Performance tips around instrumentation like django-debug-toolbar and others that can be disabled for tests. adamj.eu Update Django template fragment caches in the background Nicolas Kuttler refactors some code that uses Django's template fragment caching to use low-level cache API. kuttler.eu What is Django (Python)? A beginner-friendly overview of Django. learndjango.com My GPG setup for developing and more If you aren't digitally signing your Git commits then this article is for … -
Is Django too slow?
Does Django have "bad performance"? The framework is now is 15 years old. Is it out of date? I mean, look at these benchmarks: NodeJS/Express is consistently getting better numbers than Django. If you are learning Django in 2020 then you might be worried that you're wasting time with … -
How to make your Django project easy to move and share
You need your Django project to be portable. It should be quick and easy to start it up on a new laptop. If it isn't portable, then your project is trapped on your machine. If it gets deleted or corrupted, then you've lost all your work! This issue comes up … -
Speaking online at EuroPython 2020
An article about my first participation as a speaker at an online conference: EuroPython 2020. -
Upcoming Courses | August 2020
After the smashing success of the Django Crash Course Live, we're running two live, online courses in August. Django Best Practices the Two Scoops Way August 14th, 2020 | 9AM-4PM PST / 4PM - 11PM UTC We're offering a live, online class called Django Best Practices the Two Scoops Way. This is a live interactive class conducted via Zoom conferencing software. Daniel is going to dive deep into Django and Python. He's going to turn on the firehose of knowledge. Best of all, this is a a live event. That means attendees can ask questions, and are encouraged to do so. Material covered includes everything from code architecture to model design to API development to bottleneck analysis to user accessibility and much more. This is not a beginner tutorial, it is meant for developers who have begun to create real projects with Django. Details: Event starts at 9AM PST (4PM UTC) and ends seven (7) hours later There will be an hour long break for lunch and short breaks every hour. Class prerequisites: Knowledge of the Python programming language Django experience beyond basic tutorials A device capable of running the Zoom meeting software. Internet fast enough to join online meetings … -
Handle Default Values - Building SaaS #65
In this episode, I updated a model to handle the default duration of new tasks. This default needed to come from the Course model instead of the CourseTask model so we had to determine how best to set that data in various forms. I also fixed some drop down selection bugs that populated a form with the wrong data. We made sure that all the code was well tested. I created a new default_task_duration field to the Course model. -
How to Make Always-Installed Django Database Instrumentation
Since version 2.0, Django has provided a hook for installing database instrumentation wrapper functions. These functions are like middleware for database queries, allowing you to inspect and rewrite SQL before it is sent to the database. There are many use cases, for example: Blocking database queries in certain blocks of code, as in the feature documentation. Tracking all queries, as in Scout APM’s python agent. Rewriting queries to add extra SQL features, as used in Django-MySQL’s query hints extensions. For this post, let’s use an example wrapper function that logs a warning for slow queries. We can implement it like this: import logging import time logger = logging.getLogger(__name__) THRESHOLD_SECONDS = 1.0 def slow_query_warner(execute, sql, params, many, context): start = time.perf_counter() result = execute(sql, params, many, context) duration = time.perf_counter() - start if duration > THRESHOLD_SECONDS: logger.warning("Slow query, took %.2f seconds: %s", duration, sql) return result Then for any block of code for which we want to log about slow queries, we can use: with connection.execute_wrapper(warn_about_slow_queries): ... A small limitation of the API is that it is only available as a context manager. This means having a wrapper function that’s installed for every single query is a little bit of a … -
EuroPython 2020
EuroPython is the official European conference for the Python programming language. -
NameError: name 'os' is not defined
If you've started a new Django 3.1+ project and are using older tutorials or guides, it's likely to come across the following error on your command line: ``` NameError: name … -
Caution About Faking Django Migrations
I ran into a problem recently when trying to reconfigure my Django project’s database. I had a DateTimeField on my model that I was updating to have null=True… -
Caution About Faking Django Migrations
I ran into a problem recently when trying to reconfigure my Django project’s database. I had a DateTimeField on my model that I was updating to have null=True and blank=True. There were no rows in this table. I was able to make the migrations, but then ran into this error when running python manage.py migrate. TypeError: expected string or bytes-like object What is This TypeError? Honestly, after my research, I’m not totally sure. I believe Django was trying to put a NULL value in that DateTime table column, but since the migration hadn’t been run, NULL values were still not allowed. I found something that made my error message go away… but also introduced a bug. Django’s Migrations Table Django’s migrations actually create a table in your database where database updates are tracked. Here’s a look at that table from one of my newer projects: postgres=# \d django_migrations Table "public.django_migrations" Column | Type | Collation | Nullable | Default ---------+--------------------------+-----------+----------+----------------------------------------------- id | integer | | not null | nextval('django_migrations_id_seq'::regclass) app | character varying(255) | | not null | name | character varying(255) | | not null | applied | timestamp with time zone | | not null | Indexes: "django_migrations_pkey" … -
The Hello World of Machine Learning
Machine learning is simply a c... -
Episode 7 - Models and Managers and Querysets, Oh My!
On this episode, we will explore more about models and how to interact with data in your database. Listen at djangoriffs.com. Last Episode On the last episode, we discussed the basics of setting up a database and creating a model to store data. Working With Models To create new rows in our new database tables, we can use a model’s save method. When you save a model instance, Django will send a message to the database that effectively says “add this new data to this database table. -
How to Use Django's Parallel Testing on macOS With Python 3.8+
This post is an adapted extract from my book Speed Up Your Django Tests, available now. Django’s test command takes the --parallel flag to activate parallel testing. Unfortunately, this has never worked on Windows, and with Python 3.8 it has stopped working on macOS. Django uses the “fork” method in multiprocessing to start the new test processes. Windows does not support “fork”, and whilst macOS does, Python 3.8 changed its default to “spawn”. If the start method is not “fork” when you use the --parallel flag, Django silently switches back to serial testing. The “spawn” method works quite differently to “fork”, requiring a lot of initialization in the new test processes, so the current test framework is incompatible. This is a known issue, Ticket #31169, and it is being worked on by Ahmad A. Hussein as part of Django’s Google Summer of Code 2020. Hopefully we will merge the fix in Django 3.2. For the time being, there’s a workaround for macOS. Alternatively, you can switch to pytest, since its parallelization plugin, pytest-xdist, works on all platforms. On macOS on Python 3.8+, you can work around the lack of “spawn” support by reverting the multiprocessing start method to “fork”. You … -
Models and Managers and Querysets, Oh My!
Full show notes are available at https://www.mattlayman.com/django-riffs/7. -
What is Django (Python)?
[Django](https://djangoproject.com) is an open-source web framework written in the [Python](https://www.python.org) programming language. Named after the jazz guitarist [Django Reinhardt](https://en.wikipedia.org/wiki/Django_Reinhardt), it is used by some of the largest websites in the … -
Fun with GPT-3
Here’s a conversation I had earlier with the late Ernest Hemingway: Me: Please help me word this better: “Django is made with Python, a free and open source programming language that was made by Guido van Rossum in the 1990’s. Python’s name is a reference to the Monty Python comedy series and Django’s name is a reference to the Belgian jazz guitarist. Django can help you make any website.” Ernest Hemingway: Django is a tool that helps developers build web sites and web applications. It is made with Python, which is a programming language that allows you to write code to do things for you. Django can help you make any website. Naturally, this wasn’t with the real Hemingway, but a simulation of him with the GPT-3 transformer-based AI. The model receives the first paragraph as input, plus the “Ernest Hemingway:” prompt, and predicts the next words. I’m pretty impressed with the result, which is from the first attempt (no cherry-picking). GPT-3 Hemingway dropped the whimsical facts and got straight to the point about Django. It also decided Python should be expanded on a little more. GPT-3 is created by the Open AI project, and is an update to last … -
Create a One-Off Django Secret Key
When you bring Django into Pro... -
Django News - New Python 3.8, PyCon Africa, San Francisco Django Virtual Meetup, and more. - Jul 17th 2020
News Python Release Python 3.8.4 The fourth maintenance release for Python 3.8 with new features and optimizations. python.org Python Software Foundation News: Pip team midyear report The grant-funded team working on improvements to pip in 2020 has now passed the halfway mark. Here's an update on where are so far and what's next. blogspot.com Events Tickets are pay what you want for PyCon Africa 2020 Tickets available for the online conference August 4-8, 2020. pycon.org San Francisco Django Virtual Meetup on July 23rd There is less than one week left before this virtual Django Meetup. meetup.com Articles Invalid HTTP_HOST header errors in Django and Nginx An overview and fix for the common issue of Invalid HTTP_HOST header errors when running behind Nginx. borfast.com Pure serverless Django with django-gcloud-connectors Katie McLaughlin on configuring Django with the non-relational Google Datastore. dev.to Beyond the Cache with Python and Redis A look at using Redis for caching, sub/pub events, data streaming, as a search engine, and even a primary database. redislabs.com Tutorials Django Log In with Email not Username Update the default username/email/password pattern on login/signup with just email/password using a custom user model and django-allauth. learndjango.com How to Use psql in Docker Compose … -
Summer Break
We're taking a summer break and will be back in September with new episodes, guests, and topics. -
Django 3.1 Preview - Mariusz Felisiak
Django 3.1 Release NotesWhat's New in Django 3.1?How to Upgrade DjangoDjango DownloadWhat Python Version Can I Use with Django?SHAMELESS PLUGSLearnDjango - Free tutorials and premium books -
How to Use psql in Docker Compose
As a Django newbie, I’ve found it easy to consider the database stuff “magic” and just leave it alone. I’m starting to realize, however reluctantly, that it’s super… -
[Python] Making Website With DjangoCMS.
If you are following this website you can see we share most of the contents related to Django Framework and Python. Today here we are with another useful tutorial for making an easy website with Python. Without writing a single line of code you can make amazing websites. DjangoCMS is just like WordPress but it