Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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 -
Disable Instrumentation Packages during Tests
This post is an adapted extract from the Easy Wins chapter of my book Speed Up Your Django Tests, available now. This tip could take 8% off your tests' run time with a small configuration change! Your Django project may use some packages that add instrumentation, for example: A development tool, such as django-debug-toolbar An error handling tool, such as Rollbar or Sentry. An Application performance Monitoring (APM) tool, such as New Relic or Scout APM. Such packages often work by tracking every database query, cache operation, etc. The overhead for all this instrumentation is normally significant. For example, on a couple of project’s test suites, I’ve seen Sentry add about 8% to the total test run time. Since you often don’t need their functionality during tests, you can disable these packages in your test settings file for a speed boost. Some packages provide an option to disable their instrumentation features. If that’s not available, you can change your settings to never load them during tests. Here are some examples on how to disable such packages. If you are using a different instrumentation package, hopefully you can find similar configuration. (And please let me know the package and configuration so … -
Update Django template fragment caches in the background
The title of this post is what I originally tried to do, but the solution to the problem was to do a small refactoring and to use the low level cache API. This post will explain how I modified my approach after thinking about the problem for a while. -
Django Log In with Email not Username
Django was first released in 2005 and since then a lot has changed in web development, notably the predominant pattern at the time of using username/email/password has been simplified to … -
Announcing a Regional Discount for “Speed Up Your Django Tests”
Since I launched my book Speed Up Your Django Tests I’ve had a number of questions about possible discounts. I want to make my book affordable for all and understand that $49 is a high price tag for some. The Django community is global and I want to share knowledge with Djangonauts everywhere. So today I’m glad to announce a 50% discount for those living outside of the Top 50 Countries by GDP per capita*. Please email me with the address on my contact details page to say hi, where you live, and what you’re making with Django, and I’ll send you the discount link. (*According to the IMF 2020 table of countries’ GDP on this Wikipedia page.) I’d like to take a finer grained approach in the future, but currently Gumroad don’t offer region-targeted pricing. So I either need them to build such a feature, or create an integration using their API (and I’d rather spend more time writing). Fin Thanks to all my readers so far, —Adam -
Django News - Django 3.1 Preview - Jul 10th 2020
News Python Release 3.9.0b4 The fourth of five planned beta release previews with major new 3.9 features. python.org Events Django London Virtual Meetup on July 14th Looking for a virtual meetup to attend next week? Join Django London on July 14th featuring a talk by Django co-creator Simon Willison. meetup.com What's coming next in Wagtail? on July 15th This webinar is for anyone managing a Wagtail site, using Wagtail as an editor, developing Wagtail sites or evaluating Wagtail for a future project. zoom.us San Francisco Django Virtual Meetup on July 23rd We brought together over 160 people in our last nationwide virtual Django meetup. We're looking to go even bigger this time. Just because DjangoCon 2020 is canceled doesn't mean the show can't go on. meetup.com Articles What's New in Django 3.1? Coming in early August, async views/middleware/tests, cross-db JSONFields, updated admin, and more. learndjango.com PyDev of the Week: Philip James Philip James (@phildini) has spoken at various PyCons and DjangoCons and is the PyDev of the Week! pythonlibrary.org Refining exceptions with Context Decorators An elegant way to add more descriptive exceptions via context decorators. dev.to Arrange-Act-Assert: A Pattern for Writing Good Tests A handy way to reason about tests … -
Enrolling Students - Building SaaS #64
In this episode, we worked on a view to enroll students into a grade level for the school year. I added all the context data and used Tailwind to design the form layout to pick from a list of available grade levels. We added a variety of unit tests to prove the correctness. The enrollment page needed three pieces of data in the context to complete the form. We added the student, school_year, and grade_levels data to the context and wrote tests to show the data in there. -
Aymeric Augustin
Aymeric personal siteFractal Ideas blogAymeric on Githubdjango-sesamedjango-sequenceswebsocketsSHAMELESS PLUGSLearnDjango - Free tutorials and premium books -
What's New in Django 3.1
Django 3.1 will be released in early August 2020 and comes a number of major new features and many minor improvements including asynchronous views and middleware support, asynchronous tests, JSONField … -
How to save Base64 encoded image to Django ImageField?
I had to create an API that had to accept an image in Base64 encoded format and save it to Django image field, which requires an image file. So today I learned how to do this. Step 1: B64 to PIL The first step will be to convert this B64 image to an image file in memory, I will be using Pillow for this. You can install Pillow using this bash command. pip install pillow Make sure you have pip installed. If you’re using Linux or Mac OS, then you might have to use pip3 instead of pip. But I’m using virtual env, so who cares. after that, write this function. import base64 import io from PIL import Image def decodeDesignImage(data): try: data = base64.b64decode(data.encode('UTF-8')) buf = io.BytesIO(data) img = Image.open(buf) return img except: return None This function will return a PIL image if the B64 data is valid, or it will return None. Step 2: PIL to Djnago ImageField After getting the PIL image, wrote a function that will take this PIL image, convert it into a JPEG file buffer and then inserted it to Database instance using InMemoryUploadedFile sources: InMemoryUploadedFile What is InMemoryUploadedFile? This is basically a representation … -
How to save Base64 encoded image to Django ImageField?
In this blog, I will show you how to convert B64 encoded image to Django ImageField object. -
Too many Invalid HTTP_HOST header exception errors
Have you deployed an application to production? Are you getting too many, seemingly random Invalid HTTP_HOST header exception errors? Background I have recently deployed a Django app: served via gunicorn/Nginx onto an AWS Lightsail instance with a CloudFlare certificate for https/SSL (followed this answer on StackOverflow for configuring it) Following deployment I had a barrage of Invalid HTTP_HOST header error emails. Every. Single. Day. I looked at the Nginx configuration. But it looked identical to other configurations I have in production. Configurations that do not have this kind of error. The Nginx server block looks like: upstream dbr_project { server unix:/home/ubuntu/[..]/gunicorn.sock fail_timeout=0; } server { listen 80 default_server; listen [::]:80 default_server; server_name subdomain.example.com; if ($http_x_forwarded_proto = "http") { return 301 https://$server_name$request_uri; } ... } On further inspection, these exceptions were being caused by bots. Example user agent strings: HTTP_USER_AGENT = 'Mozilla/5.0 (compatible; Nimbostratus-Bot/v1.3.2; http://cloudsystemnetworks.com)' HTTP_USER_AGENT = 'masscan/1.0 (https://github.com/robertdavidgraham/masscan)' So the cause looks external. And the “dirty” fix I resorted to is to stop reporting this class of error. Fix I’ve followed this answer on StackOverflow to stop reporting, or “suppress”, this error. My previous LOGGING config (which I stripped down to a bare minimum for this post) looked like: 1 … -
Django Testing Toolbox
What are the tools that I use to test a Django app? Let’s find out! You might say I’m test obsessed. I like having very high automated test coverage. This is especially true when I’m working on solo applications. I want the best test safety net that I can have to protect me from myself. We’re going to explore the testing packages that I commonly use on Django projects. We’ll also look at a few of the important techniques that I apply to make my testing experience great. -
Custom Response Header in Django
In this post, I'll be showing how you can add custom header to response in Django. -
Custom Response Header in Django
So I was wondering on how to build a habit of writing blogs daily, and my friend suggested that we could write about the little things we learn everyday, so we decided to start a series called Today I Learned where we will write about the little things we learn everyday, and thus build a habit I was creating this REST API for one of my clients and I was thinking what is the proof that I made this app, and I was totally blank because only proof I will have is the payment I will be receiving from the client. So I thought, what if I implant something in the response header that will scream that I have created this API or web-app or whatever. In this post, I will be documenting how we can create our own header attribute to responses in Django. Method 1 - Local Header In this you can add a custom header attribute to one response. For example, imaging you are creating an auth APi and you want to send an encrypted token as a response header. For that the view function will be something like this. def auth(req): # DO AUTH RELATED STUFF … -
Deploying and Hosting a Machine Learning Model with FastAPI and Heroku
This tutorial looks at how to deploy a machine learning model, for predicting stock prices, into production on Heroku as a RESTful API using FastAPI. -
Django News - New Django & Python Releases - Jul 3rd 2020
News Django bugfix releases issued: 3.0.8 and 2.2.14 Another bugfix release for Django 3.0 and 2.2. Django 3.1 comes out in August! djangoproject.com Python 3.7.8 and 3.6.11 released The 3.7.8 is expected to be the last bugfix release for the 3.7.x series. Future releases will focus on security fixes. blogspot.com Python Software Foundation News: 2020 Python Software Foundation Board of Directors Election Retrospective and Next Steps blogspot.com Articles Making Django App Publicly Accessible With Ngrok Ngrok is a great way to share your local Django runserver with anyone you give the link to. It makes having demo or testing webhooks locally possible. dev.to Python async frameworks - Beyond developer tribalism From Tom Christie, creator of Django REST Framework, a thoughtful overview of the async Python landscape. encode.io Store Data With Models See how to take data and store it into a database so that your application can use that data or display it later. mattlayman.com How to add a .well-known URL to your Django site A quick guide to what /.well-known/ URLs are and how to create them. adamj.eu How to find what you want in the Django documentation Many beginner programmers find the Django documentation overwhelming. mattsegal.dev Lack of … -
I'm Teaching A Live Online Django Crash Course
Course Announcement On July 16th and 17th of 2020, I'll be running a live instruction of my beginner-friendly Django Crash Course. This is a live interactive class conducted via Zoom conferencing software. We're going to walk through the book together with students. If you get stuck, there will be at least two members of the Feldroy team available to help. Each course day will have two sessions each 3 hours long, as well as an hour-long break between sessions. Attendees Receive Hours of instruction in building web apps by noted authors and senior programmers An invite to both July 16th and July 17th class days The Django Crash Course e-book (if you already bought one, we'll send you a discount code for $19.99 off the online class) Membership in our forthcoming online forums when they are activated Class Prerequisites Basic knowledge of the Python programming language Computer where you are allowed to install software (No work restrictions) Internet fast enough to join online meetings Topics Covered Setting up a development environment Cookiecutter for rapidly accelerating development Django Forms Class-Based Views Models Templates Admin Writing Django tests PyTest Factories Best practices per Two Scoops of Django Proven patterns for avoiding duplication … -
Django Login and Logout Tutorial
In this tutorial we'll learn how to configure login/logout functionality with Django's the built-in [user authentication system](https://docs.djangoproject.com/en/4.0/topics/auth/). This is the first in a three-part series that also covers [signup](https://learndjango.com/tutorials/django-signup-tutorial) and …