Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Debugging async Django under Uvicorn with Pycharm
If you deploy Django async under ASGI, chances are you need an ASGI server like Uvicorn. In production, you can use Uvicorn with Gunicorn, but in development you might want to use Uvicorn standalone, which can also run programmatically from a Python script. This gives also the ability to debug your asynchronous Django project locally with any IDE. In this short guide you'll learn how to debug Django under Uvicorn with Pycharm. Running Uvicorn programmatically As a first step, create a Python script in your project root. I call mine server.py. In this file we import and run Uvicorn: import uvicorn if __name__ == '__main__': uvicorn.run("async_django.asgi:application", reload=True) Here I assume we have a Django project in the async_django folder, where we can also find a file named asgi.py, which is the ASGI application for our Django project. Once the script is ready we move to configure Pycharm. Configuring Pycharm to debug Django In Pycharm, open up the Run menù and click on Edit configurations. Here we create a new configuration for Python, to run our server.py: The Script path configuration should point to the path where server.py lives. Once done you're ready to debug your Django async project. Debugging async … -
Managing a Django Project with Poetry
Poetry is relatively new packaging and dependency manager. It makes it very easy to upload libraries to PyPI, manage dependencies visually, and has a couple of handy features. Today, I'm not going to do a deep dive into how Poetry works and all its features. Today I just want to focus on how to configure it for a Django project. -
Managing a Django Project with Poetry
Poetry is relatively new packaging and dependency manager. It makes it very easy to upload libraries to PyPI, manage dependencies visually, and has a couple of handy features. Today, I'm not going to do a deep dive into how Poetry works and all its features. Today I just want to focus on how to configure it for a Django project. -
Django: adding extra context data to a CreateView
Welcome back to another episode of my Django mini-tutorials! In this post we see how to add extra context data to a Django CreateView. What context there is in a CreateView? I already touched CreateView in this tutorial. In brief, CreateView is a Django class-based view complete of everything you need to create HTML forms in your Django pages. Here's how a CreateView looks like: class TicketCreate(CreateView): model = Ticket fields = ["subject", "message", "priority", "attachment"] success_url = reverse_lazy("clientarea") In this class-based view you specify a model to operate on, the fields you want to expose, and an optional success_url to redirect the user to, once the form has been successfully submitted. Now, a CreateView usually renders also a default template (unless you change it), which by convention takes the name of the model, followed by the word "form". For this CreateView for example, the template is ticket_form.html, which should be created beforehand in the template folder. Once rendered, the template gets a context, which in this case will include a form object which we can then render in the template. So, CreateView renders a form for editing the model, what if we want to include extra context data? Adding … -
Django News - New Django Girls Leadership - Oct 29th 2020
News Ola & Ola step down from Django Girls Foundation The Django Girls Foundation welcomed a new team of trustees: Anna, Aisha, Claire, Leona, and Rachell ❤️. djangogirls.org Python Software Foundation News: Python Software Foundation Fellow Members for Q3 2020 🎉 Congratulations to Katia Lira (DEFNA Board member), Mariatta Wijaya (DjangoCon US Keynote speaker), and other Pythoniasts for being picked as PSF Fellow Members. blogspot.com DjangoCon US 2020 Video ⏰ The deadline has been extended. Please take a minute to record a short video for the virtual conference this year. defna.org Articles A Django REST API in a Single File The third in a series of writing Django apps in a single file, following previous posts on synchronous and asynchronous use cases. adamj.eu How to Setup Django with React A detailed guide to the various steps required to have React play well with Django. mattsegal.dev Password Reset Views in Django Learn how to setup password reset views with django.contrib.auth. dev.to Podcasts PythonBytes #204 - Take the PSF survey and Will & Carlton drop by Django Fellow Carlton Gibson and DSF Board Member Will Vincent talk about moving from prototype to production in Django as well as all things deployment. pythonbytes.fm … -
Sending Invites - Building SaaS #77
In this episode, I worked on the form that will send invites to users for the new social network app that I’m building. We built the view, the form, and the tests and wired a button to the new view. The first thing that we do was talk through the new changes since the last stream. After discussing the progress, I took some time to cover the expected budget for the application to get it to an MVP. -
MongoDB - Aaron Bassett
@aaronbasett on TwitterAaron on GithubHTTP Headers from ~10 Million domains - An Open DatasetRealmWildAid AppEverything You Know About MongoDB is WrongCan You Keep a Secret? PyConline AU 2020django-loginasdjango-hijackSupport the ShowOur podcast does not have a sponsor and is a labor of love. To support the show, please consider purchasing one of the books on LearnDjango.com or suggest one to a friend. -
Generating random avatar images in Django/Python
tl;dr; <img src="/avatar.random.png" alt="Random avataaar"> generates this image: (try reloading to get a random new one. funny aren't they?) When you use Gravatar you can convert people's email addresses to their mugshot. It works like this: <img src="https://www.gravatar.com/avatar/$(md5(user.email))"> But most people don't have their mugshot on Gravatar.com unfortunately. But you still want to display an avatar that is distinct per user. Your best option is to generate one and just use the user's name or email as a seed (so it's always random but always deterministic for the same user). And you can also supply a fallback image to Gravatar that they use if the email doesn't match any email they have. That's where this blog post comes in. I needed that so I shopped around and found avataaars generator which is available as a React component. But I need it to be server-side and in Python. And thankfully there's a great port called: py-avataaars. It depends on CairoSVG to convert an SVG to a PNG but it's easy to install. Anyway, here's my hack to generate random "avataaars" from Django: import io import random import py_avataaars from django import http from django.utils.cache import add_never_cache_headers, patch_cache_control def avatar_image(request, seed=None): if … -
Generating random avatar images in Django/Python
tl;dr; <img src="/avatar.random.png" alt="Random avataaar"> generates this image: (try reloading to get a random new one. funny aren't they?) When you use Gravatar you can convert people's email addresses to their mugshot. It works like this: <img src="https://www.gravatar.com/avatar/$(md5(user.email))"> But most people don't have their mugshot on Gravatar.com unfortunately. But you still want to display an avatar that is distinct per user. Your best option is to generate one and just use the user's name or email as a seed (so it's always random but always deterministic for the same user). And you can also supply a fallback image to Gravatar that they use if the email doesn't match any email they have. That's where this blog post comes in. I needed that so I shopped around and found avataaars generator which is available as a React component. But I need it to be server-side and in Python. And thankfully there's a great port called: py-avataaars. It depends on CairoSVG to convert an SVG to a PNG but it's easy to install. Anyway, here's my hack to generate random "avataaars" from Django: import io import random import py_avataaars from django import http from django.utils.cache import add_never_cache_headers, patch_cache_control def avatar_image(request, seed=None): if … -
Application Examination
Full show notes are available at https://www.mattlayman.com/django-riffs/9. -
How to setup Django with React
It's not too hard to get started with either Django or React. Both have great documentation and there are lots of tutorials online. The tricky part is getting them to work together. Many people start with a Django project and then decide that they want to "add React" to it … -
Django News - Some of our favorite DjangoCon Europe 2020 videos - Oct 23rd 2020
News Sponsor @python on GitHub Sponsors The PSF joined GitHub's sponsor's program. Their goal is to raise enough money to help support the development of CPython. github.com Events PyTexas 2020 Schedule PyTexas is this weekend, Oct 24th & 25th, and is free to attend. Donations and t-shirts may still be available. pytexas.org San Francisco Django Virtual Meetup Join the San Francisco Django Meetup Group on October 28th for a free virtual meetup. meetup.com Articles A Year in the Life of a DSF Board Member An overview of 2020 activities for the Django Software Foundation Treasurer position. wsvincent.com Why You Should Pay for Open Source Will Heinemann discusses making a strong case for supporting (and paying for) open-source and a recent Wagtail Space 2020 video on the topic. wagtail.io Simplifying Django deployments on Heroku Eric Matthes, author of Python Crash Course, on his newly created Heroku Python buildpack that automates as much of the deployment process as possible ehmatthes.com Comprehending Class-Based Views in Django - Creating a CBV The second in a series of articles on how CBVs work under-the-hood. brennantymrak.com feincms may still be relevant feincms is one of the original Django CMS's and still in use. This article highlights … -
Developing a Single Page App with FastAPI and React
In this tutorial, you'll be building a CRUD app with FastAPI and React. -
gettext, JSX and ES6 template literals
gettext, JSX and ES6 template literals I really like using gettext to translate hardcoded strings into other languages. Django’s translations functionality relies on it as well. Unfortunately, the xgettext executable which is responsible to collect translatable strings in your code has a bug where it just stops processing files when encountering ES6 template literals inside JSX tags. Support for ES6 template literals was added earlier this year but combining those literals with JSX still doesn’t work. I wrote a small Python script to extract *gettext calls from JavaScript files; the current version is here. The idea is to find all JavaScript files using git ls-files "*.js", using a regular expression to find *gettext calls and write the output to a place where Django’s ./manage.py makemessages finds it. I’m certain the code will break too with strange error messages in the near future but it seems to work well, for the moment. Here’s the current version of the code (hopefully) for your enjoyment: #!/usr/bin/env python3 import re import subprocess def js_files(): res = subprocess.run( ["git", "ls-files", "*js", "*mjs"], capture_output=True, encoding="utf-8", ) return res.stdout.splitlines() def gettext_calls(file): with open(file, encoding="utf-8") as f: return [ match[0] for match in re.findall( r"""\b(\w*gettext\(\s*(['"]).+?\2\s*\))""", f.read(), ) ] … -
User Authentication
In the previous Understand Django article, we learned about the structure of a Django application and how apps are the core components of a Django project. In this article, we’re going to dig into Django’s built-in user authentication system. We’ll see how Django makes your life easier by giving you tools to help your web application interact with the users of your site. From Browser To DjangoURLs Lead The WayViews On ViewsTemplates For User InterfacesUser Interaction With FormsStore Data With ModelsAdminister All The ThingsAnatomy Of An ApplicationUser Authentication Authentication And Authorization We need to start with some terms before we begin our study. -
A Year in the Life of a DSF Board Member
What Django Software Foundation Board Member's actually do. -
Episode 9 - Application Examination
On this episode, we will study the structure of a Django application. Applications are the core components that make up a Django project. Listen at djangoriffs.com. Last Episode On the last episode, we focused on the built-in Django administrator’s site. We’ll saw what it is, how you can configure it, and how you can customize it to serve your needs. What Is An Application? In Django parlance, a “web application” is a Django project. -
On using Markdown with Sphinx - onward to Evennia 0.9.5
Last post I wrote about the upcoming v1.0 of Evennia, the Python MU* creation engine. We are not getting to that 1.0 version quite yet though: The next release will be 0.9.5, hopefully out relatively soon (TM). Evennia 0.9.5 is, as you may guess, an intermediary release. Apart from the 1.0 roadmap just not being done yet, there is one other big reason for this - we are introducing documentation versioning and for that a proper release is needed as a base to start from. Version 0.9.5 contains everything already in master branch, so if you have kept up-to-date you won't notice too much difference. Here are some highlights compared to version 0.9: EvMore will paginate and properly handle both EvTables and database query output. For huge data sets, pagination can give a 100-fold speed-increase. This is noticeable e.g. in the scripts and spawn/list commands, once you have a lot of items.EvMenu templating language, to make it easier to create simpler menus. Webclient improvements: Cleanup of interface and the ability for players to save/load their pane layouts from the client. The developer can still provide a default for them to start out with. MUD/Evennia Intro wizard to the tutorial world to … -
7 reasons Django Web Framework is Perfect for Startups
If your startup is obsessed with its technology stack, then you are not alone. Every emerging CTO wants the most value-oriented programming language, scalable web framework, and expert developers. This article will leave behind the programming language and talented developers and talk about one of the best things in the technology stack for startups – […] The post 7 reasons Django Web Framework is Perfect for Startups appeared first on BoTree Technologies. -
Django News - DjangoCon EU Videos Available - Oct 16th 2020
News DjangoCon Europe 2020 - Videos now live All 30 videos are now available on YouTube from this year's conference. youtube.com Events PyTexas 2020 PyTexas is Oct 24th & 25th and online this year will be streamed for free or a donation. Don't miss the t-shirts which are very nice looking. pytexas.org Articles How to Mock Environment Variables in PyTest Three things most Django projects need--mocks, environment variables and PyTest--covered by Adam Johnson. adamj.eu Django's transaction.atomic() It's not always as atomic as you might think! charemza.name Weeknotes 2020 WK 41 - OMG Timezones Django Fellow Carlton Gibson's weekly notes on all things Python/Django, with a focus on timezone support. noumenal.es We need to talk about GitHub On the current state of GitHub and mono/poly cultures. thea.codes Upgrading Python Homebrew packages using pip A quick tip from Simon Willison on updating Python via Homebrew. simonwillison.net Prevent Unintended Data Modification With django-read-only - Adam Johnson Tips to using the new django-read-only package, which provides a read-only mode for Django’s database layer. adamj.eu Django log management with Elastic and Kibana A hands-on guide to creating log management with Elasticsearch, Filebeat, and Kibana in a Django project. koky.ir Sponsored Link Mystery Science Theatre 3000 … -
Running Django on DigitalOcean's App Platform
This article looks at how to deploy a Django application to DigitalOcean's App Platform. -
Capped Social Network - Building SaaS #76
In this episode, I started a new project to build a different kind of social network. This social network will contain a max number of connections to encourage thoughtful choice when growing your personal network. We talked MVP features and put in the basics of a Django app. I had a wild thought to build a social network with a capped number of connection in the hope that users would choice their connections based on people that they really care about. -
A Django REST API in a Single File
I previously covered writing a Django application in a single file, for both synchronous and asynchronous use cases. This post covers the angle of creating a REST API using Django in a single file. Undeniably, REST API’s are a very common use case for Django these days. Nearly 80% of this year’s Django community survey respondents said they use Django REST Framework (DRF). DRF is great for building API’s and provides many of the tools you’d want in a production-ready application. But for building a very small API, we can get by solely with tools built into Django itself. Without further ado, our example application is below. You can save it as app.py, and run it with python app.py runserver (tested with Django 3.1). An explanation follows after the code: import os import sys from dataclasses import dataclass from django.conf import settings from django.core.wsgi import get_wsgi_application from django.http import HttpResponseRedirect, JsonResponse from django.urls import path from django.utils.crypto import get_random_string settings.configure( DEBUG=(os.environ.get("DEBUG", "") == "1"), ALLOWED_HOSTS=["*"], # Disable host header validation ROOT_URLCONF=__name__, # Make this module the urlconf SECRET_KEY=get_random_string( 50 ), # We aren't using any security features but Django requires this setting MIDDLEWARE=["django.middleware.common.CommonMiddleware"], ) @dataclass class Character: name: str age: … -
Ethical Ads - David Fischer
David Fischer personal siteEthicalAds.ioAdvertising on Read the Docs Community Sitesethical-ad-server on GithubSupport the ShowOur podcast does not have a sponsor and is a labor of love. To support the show, please consider purchasing one of the books on LearnDjango.com or suggest one to a friend. -
Django London Meetup 2020
The Django London Meetup group is a social meetup, that hold a gathering the 2nd Tuesday of each month.