Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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. -
Prevent Unintended Data Modification With django-read-only
Last week I released a new Django package, django-read-only. It provides a read-only mode for Django’s database layer. This can be useful to reduce the risk of giving developers access to your production instances. Access to manage.py shell on production allows you to iterate faster when creating new features, migrations, and backfills. But with great power comes great accident potential. It’s all too easy to mix up terminal sessions and run the wrong thing on production. Even if the individual chance of making such a mistake is small, multiplying it by team size and time, the chance of a mistake can become almost certain, and the potential cost can be huge. Rather than locking your team members out of production, you can protect against these mistakes with django-read-only. The package uses some always-installed database instrumentation to block database access when its read-only mode is active. You can then enable read-only mode for interactive production sessions via an environment variable or setting, so when developers access production writes are disabled by default. Read-only mode can be disabled, so the occasional manual data fix is still possible. For example, if the environment variable was set, we couldn’t log into the shell and … -
Python 3.9: What's New
This article looks at the new features in Python 3.9 and how they can be implemented. -
Django News - Django Technical Board Results and Python 3.9 released - Oct 9th 2020
News Django Technical Board Election Results 2020 The winners of the first Django Technical Board Election after the adoption of DEP-10 are: Andrew Godwin Adam Johnson Markus Holtermann Tom Forbes James Bennett djangoproject.com Python Release Python 3.9.0 Python 3.9.0 is the newest major release of the Python programming language, and it contains many new features and optimizations. python.org Wagtail Telepath - the next evolution of StreamField Adding the missing link to provide richer client-side behaviour in StreamField and beyond. wagtail.io Events PyTennessee 2021 CFP closes on October 13 PyTennessee is a yearly regional Python conference in Nashville, TN. The conference was started in 2014 by Jason Myers and Will Golden, and has been a staple of the conference calendar every year since. PyTennessee 2021 will be our 8th year, and our first year doing a purely virtual conference! papercall.io Articles Django Stripe Subscriptions Use Stripe Checkout to add subscriptions to a Django project. testdriven.io Django Slug + ID URLs: Copying Dev.to's URL pattern to Copying the dev.to URL design of a username, slug, and hashed value in Django. dev.to A Django project blueprint to help you learn by doing A description of a Django project for beginners, which you can … -
Use Django in Jupyter
Below is a simple method to us... -
Make A Landing Page - Building SaaS #75
In this episode, I added a landing page design to the app that I’m building. By using a Tailwind CSS landing page template, I could fit the design in with my existing CSS tools. I showed some available templates that I discovered while researching for Tailwind-based landing pages. Once I found a decent template, I copied the source of sample landing page into my index page template. Since I copy and pasted from the landing page, the initial look was terrible. -
Testing Flask Applications with Pytest
This articles serves as a guide to testing Flask applications with pytest. -
Django Bootcamp - October 2020
Learn Django little by little ...