Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Serving Static Files
In the previous Understand Django article, I described how Django gives us tools to run code for any request using the middleware system. Our next focus will be on static files. Static files are vital to your application, but they have little to do with Python code. We’ll see what they are and what they do. From Browser To DjangoURLs Lead The WayViews On ViewsTemplates For User InterfacesUser Interaction With FormsStore Data With ModelsAdminister All The ThingsAnatomy Of An ApplicationUser AuthenticationMiddleware Do You Go? -
Our Top 20 Blogs in 2020
We’ve published summaries of our most popular blog posts before (see Top 19 of 2019 and Top 18 of 2018), but this time, we’re taking it a step further. We’re sharing the 20 most popular posts in 2020, regardless of the year the post was originally published. And some of these have been around a while! Based on total pageviews, here are the blogs that rose to the top of the popularity list, from most viewed to least viewed. -
How to Set Up report-uri.com on Django
In recent years browsers have gained many powers to report back problems they encounter on your site, such as: Network Error Logging (NEL) can report bad HTTP statuses, expired TLS certificates, etc. Content Security Policy can report banned resources found on your site. Deprecation reports can tell you that you’re using web API’s that will soon be removed. Browsers send these reports to URI’s listed in specific security headers, including the exiperimental Report-To header. These are really useful since they can uncover issues that would otherwise go unseen. A service for collecting, parsing, and making sense of these reports is report-uri.com. It’s run by Scott Helme a security researcher who also made the useful free tool securityheaders.com. It makes a lot of sense to use a separate service for receiving browser reports, since if you have a problem on your own site, it’s likely you’d have problems collecting the reports too! Yesterday I set up report-uri.com on my new Django project db-buddy.com. Here’s how I did it. Note: I added the headers from within Django. This makes sense for me since I’m deploying on Heroku and serve all URL’s from Django, including static assets via Whitenoise. If your site is … -
Designing Engineering Organizations
How should you structure a larger engineering organization, one with dozens (or hundreds) of engineers? There are many tradeoffs to consider, and no single right answer. But, there are some structures that work better than others. -
Better Exception Output in Django’s Test Runner With better-exceptions
Today I learned about the better-exceptions pacakage. It makes exception output better, providing more context and colourization on the terminal. If you’re using Django’s test framework, you can install better-exceptions during your test runs. It makes it the plain assert statement much more usable. Plain asserts are clearer to write and read than the various self.assert* functions, so a definite win for tests. pytest’s assert statement rewriting is similar to better-exceptions, and it’s definitely a “killer feature” for pytest users. Whilst I recommend pytest, it can be hard to port existing projects, so using better-exceptions is a nice compromise. Adding better-exceptions To Django Test Runs First, you’ll want a custom test runner class. If you don’t already have one, create one as below, in a file like example/test.py. Inside that the test runner’s run_tests() method, you can use a monkey-patch to install better-exceptions into the unittest TestResult class, which is responsible for output of tests. There’s a snippet in the better-exceptions documentation, which I’ve made Python-3-only. Putting it all together: from unittest.result import TestResult import better_exceptions from django.test.runner import DiscoverRunner class ExampleTestRunner(DiscoverRunner): def run_tests(self, *args, **kwargs): # Enable better-exceptions for better display of exceptions # https://github.com/Qix-/better-exceptions#use-with-unittest def exc_info_to_string(self, err, test): … -
How to Override the gunicorn Server Header
In all current releases of the popular WSGI server gunicorn, the Server header reports the complete version of gunicorn. I spotted this on my new project DB Buddy. For example, with httpie to check the response headers: $ http https://db-buddy.herokuapp.com -ph HTTP/1.1 200 OK ... Server: gunicorn/20.0.4 ... Reporting the version of server software is not recommended as it is a security risk. Fastly list Server and other vanity headers first in their article The headers we don’t want. In many setups, gunicorn’s Server header will be overwritten. For example if you’re using Nginx, it will replace Server with its own version (disable that with its server_tokens directive). But my app is running on Heroku which preserves the gunicorn Server header. Because of the security risk, there has been a long ongoing gunicorn issue to remove the version from the gunicorn header, leaving it as Server: gunicorn. The Pull Request to remove the version was merged nearly a year ago but is still pending release. Until then, we can use the workaround suggested in the original issue: monkey-patch the SERVER_SOFTWARE attribute that gunicorn uses to fill in the Server header. I’m configuring gunicorn with a submodule of my app’s package, … -
Happy new years 2021! Evennia things to come this year
Another year passed with Evennia, the Python MU* creation system. The past year saw a lot of bug fixing and more gradual additions and in September we released version 0.9.5. This was an intermediary version on our way to 1.0. Time to look forward to next year. On my development horizon for 2021 are the main new features planned for v1.0. Some of these are rather big things I've wanted to get around to for a while. They are all happening in the develop branch of Evennia, which is currently not recommended for general use.SessionDB: In the current Evennia, Sessions (the representation of a single client connection) is an in-memory entity. This is changing to be a database-backed entity instead. One will be able to typeclass Sessions like other entities for easier overriding. This change also means that there will be one single point of session-id (the django-session), alleviating some reported issues where the Portal- and Server-side sessions have drifted out of sync. It will also make it a lot easier to support auto-logins, also across server reboots. Db-backed Sessions will also simplify the Portal-Session interaction a lot. Script refactor: The Scripts will see some refactoring, mainly because they are used more as … -
Django News - 2020 Year-in-Review - Jan 1st 2021
Introduction 2020 in Review Thanks to all of our newsletter subscribers. We grew to over 1,500 readers and an average open rate of 63%+ which is considered very high for newsletters. We're looking forward to 2021 and continuing to provide news, articles, and projects in the Django community. django-news.com News 2020 Malcolm Tredinnick Memorial Prize awarded to Ken Whitesell Ken Whitesell was awarded the 2020 Malcolm Tredinnick Memorial Prize for his many contributions to the Django community. This year we received the highest number of nominations ever received for the Malcolm Tredinnick Memorial Price with some being nominated twice, three times, and the highest being six times. djangoproject.com Channels security release issued: 3.0.3 Channels 3.0.3 is a security release and we encourage all users of Channels to upgrade as soon as possible. djangoproject.com Django News newsletter sponsorship If you'd like to reach 1,500+ engaged Django developers with news, projects, job listings, and more consider sponsoring our newsletter. Rates and availability are all online. django-news.com Articles Django Best Practices: Security The most-clicked article was by Will on Security, providing a list of top factors to consider in any Django project and tips for locking-down security. learndjango.com Docker & Django local development: … -
Customer Docs - Building SaaS #85
In this episode, I integrated customer documentation into the app. I showed how to build Sphinx documentation into a Django project, then created a help view to link to the docs. Finally, I added documentation building to the deployment process. I previously created a Sphinx documentation project to hold docs for my app, but I had not hooked the docs into my project yet. Before hooking it in, I explained how Sphinx works and how I customized the documentation to fit with my project. -
Continuous Delivery in an Agile World
This article looks at what Continuous Delivery is, why it's a competitive advantage, and what the process looks like. -
AI is catching up to the hype
One of the major trends I’ve been thinking about a lot this year is that the reality of AI has starting catching up to the hype. This thought has been percolating in my brain for a while, and finally bubbled out into a comment on MetaFilter. I’m publishing it here, as well. -
Django News - GeoDjango and Hotwire! - Dec 24th 2020
News Python Release Python 3.8.7 Python 3.8.7 is a bugfix release. python.org Hotwire: HTML Over The Wire Hotwire is an alternative approach to building modern web applications without using much JavaScript by sending HTML instead of JSON over the wire. The Basecamp folks put up a marketing website announcing some new OSS tools which promote sending HTML instead of JSON over the wire. hotwire.dev Django Backend Support for Hotwire Discussion If you are curious about how to use Hotwire with Django, checkout this discussion. hotwire.dev Events PyCon Us 2021 Call for Proposals is Open! PyCon US 2021 will be virtual but the call for proposals is open now until February 12, 2021. blogspot.com Articles Creating Custom Postgres Data Types in Django Some tips on creating new data types in Postgres and bringing them into a Django application. pganalyze.com How to Mock the Current Date and Time in Python by Adam Johnson If you’re testing Python code that relies on the current date or time, you will probably want to mock time to test different scenarios but doing so isn't that easy. Adam Johnson shares some tips on how to overcome this. adamj.eu Learn about ghapi, a new third-party Python client … -
Web Authentication Methods Compared
This article looks at the most commonly used web authentication methods. -
Search & GeoDjango - Paolo Melchiorre
Paolo’s personal website20tabGithub profileTwitter profileDjangoCon Europe 2020 - A Pythonic Full-Text SearchDjangoCon Europe 2019 - Maps with GeoDjango, PostGIS and LeafletFull-Text Search in Django with PostgreSQLWorld Food ProgramMaps with Django (part 1): GeoDjango, SpatiaLite and LeafletSupport the ShowThis podcast is a labor of love and does not have any ads or sponsors. To support the show, consider purchasing or recommending a book from LearnDjango.com or signing up for the free weekly Django News newsletter. -
Refactoring Enrollment - Building SaaS #84
In this episode, I decided to redesign a portion of the application flow. I wasn’t pleased with how users would enroll students for their grades so I refactored the school year page into a flow that worked better. Note: My internet connection was not good during this stream. Thankfully, the audio is fine and reading code is very possible because the background doesn’t need to change much. My apologies for the low quality. -
Django Chat - E81
A podcast on the Django Web Framework by William Vincent and Carlton Gibson. -
Testing Django with Cypress, how nice!
When I discovered Cypress in 2017 my life as a developer changed. I was not afraid to write functional tests anymore, and since then I applied this tool to any web framework I worked with. In particular, I've been working almost exclusively with Django these days, and even if JavaScript does not fare so well in Python developers circle, when it comes to testing a Django/JavaScript project my tool of choice is always Cypress. In this post I share a couple of recipes for testing Django with Cypress, with a focus on the authentication flow. Testing Django login with Cypress As suggested in the Cypress documentation, you may want to test the authentication flow of a web application no more than once with the UI. This means you create a single test somewhere, where you check your login page: describe("Login", () => { before(() => { cy.fixture("users.json").as("mockedUsers"); }); it("Can login through the UI", function () { cy.visit("/login/"); cy.get("input[name='username']").type(this.mockedUsers[0].fields.email); cy.get("input[name='password']").type("dummy_password"); cy.get("form").submit(); cy.getCookie("sessionid").should("exist"); }); }); As for the fixtures, you can use the same data from Django dumpdata, aply saved in cypress/fixtures/fixture_name.json. Testing Django login without the UI So far so good for the first login test. What if you now need … -
RobotFramework, Chromedriver and Docker
One of my team implemented [RobotFramework](https://robotframework.org) support for automated browser testing of our platform a while ago. At the time, we were using [Codeship](https://codeship.com) Basic, and I built a [helper](https://schinckel.net/2020/05/27/django-and-robot-framework/) to run a robot test suite within a tox environment. It was all good, because `chromedriver` and all it's dependencies were already installed. But time passes, and we needed to move to Codeship Pro. Which has some neater features, but required me to build docker images for everything. We already use docker for deployment, but I didn't really want to build a bunch of distinct images just for testing that re-implemented the same stuff that we have in our deployment images. Even just appending new stuff to them means that things could turn out to be a pain in the arse to manage. And getting chromedriver installed into a docker image is not neat. I did find a [docker image that just has an instance of chromedriver](https://github.com/RobCherry/docker-chromedriver/blob/master/Dockerfile), and exposes that. But getting that to work with robot was still a bunch of work. After much experimentation, I was able to get the connections between everything to work. First, we need to have the chromedriver container running: {% highlight bash %} … -
RobotFramework, Chromedriver and Docker
One of my team implemented [RobotFramework](https://robotframework.org) support for automated browser testing of our platform a while ago. At the time, we were using [Codeship](https://codeship.com) Basic, and I built a [helper](https://schinckel.net/2020/05/27/django-and-robot-framework/) to run a robot test suite within a tox environment. It was all good, because `chromedriver` and all it's dependencies were already installed. But time passes, and we needed to move to Codeship Pro. Which has some neater features, but required me to build docker images for everything. We already use docker for deployment, but I didn't really want to build a bunch of distinct images just for testing that re-implemented the same stuff that we have in our deployment images. Even just appending new stuff to them means that things could turn out to be a pain in the arse to manage. And getting chromedriver installed into a docker image is not neat. I did find a [docker image that just has an instance of chromedriver](https://github.com/RobCherry/docker-chromedriver/blob/master/Dockerfile), and exposes that. But getting that to work with robot was still a bunch of work. After much experimentation, I was able to get the connections between everything to work. First, we need to have the chromedriver container running: {% highlight bash %} … -
Update value only if present
We have a bunch of integrations with external systems, and in most of these cases we are unable to use Oauth, or other mechanisms that don't require us to store a username password pair. So, we have to store that information (encrypted, because we need to use the value, rather than just being able to store a hashed value to compare an incoming value with). Because this data is sensitive, we do not want to show this value to the user, but we do need to allow them to change it. As such, we end up with a form that usually contains a username and a password field, and sometimes a URL field: {% highlight python %} class ConfigForm(forms.ModelForm): class Meta: model = ExternalSystem fields = ('username', 'password', 'url') {% endhighlight %} But this would show the password to the user. We don't want to do that, but we do want to allow them to include a new password if it has changed. In the past, I've done this on a per-form basis by overridding the `clean_password` method: {% highlight python %} class ConfigForm(forms.ModelForm): class Meta: model = ExternalSystem fields = ('username', 'password', 'url') def clean_password(self): return self.cleaned_data.get('password') or self.instance.password … -
Update value only if present
We have a bunch of integrations with external systems, and in most of these cases we are unable to use Oauth, or other mechanisms that don't require us to store a username password pair. So, we have to store that information (encrypted, because we need to use the value, rather than just being able to store a hashed value to compare an incoming value with). Because this data is sensitive, we do not want to show this value to the user, but we do need to allow them to change it. As such, we end up with a form that usually contains a username and a password field, and sometimes a URL field: {% highlight python %} class ConfigForm(forms.ModelForm): class Meta: model = ExternalSystem fields = ('username', 'password', 'url') {% endhighlight %} But this would show the password to the user. We don't want to do that, but we do want to allow them to include a new password if it has changed. In the past, I've done this on a per-form basis by overridding the `clean_password` method: {% highlight python %} class ConfigForm(forms.ModelForm): class Meta: model = ExternalSystem fields = ('username', 'password', 'url') def clean_password(self): return self.cleaned_data.get('password') or self.instance.password … -
Django News - Wagtail in the news - Dec 18th 2020
News Announcing the Location for PyCon US 2022/2023 PyCon US 2022 and 2023 will be in Salt Lake City, Utah. blogspot.com Wagtail 2.11.3 release notes Wagtail 2.11.3 includes four bug fixes and one upgrade consideration to look at before you upgrade. wagtail.io Events Wagtail Documentation Sprint We're running a two-day sprint, focused on Wagtail's documentation, and we'd love you to come. It will be on January 7th and 8th 2021 and will take place in Torchbox's offices in the UK (depending on what's safe by then), as well as remotely. google.com Articles Django Session-based Auth for Single Page Apps A look at how to authenticate Single-Page Applications (SPAs) with Django session-based authentication. Suitable for a frontend built with React/Vue/Angular/etc. testdriven.io Introducing django-version-checks by Adam Johnson Notes on the recently released django-version-checks package and why it came to be. adamj.eu 12 Days of Performance by REVSYS An oldie but a goodie. revsys.com Understanding Django: Middleware Do You Go? Another in Matt Layman's series on Understand Django, this is a deep look at middleware. mattlayman.com Useful Flake8 Plugins for Python Linting This is a nice introduction to Flake8 and many useful plugins. dev.to Design Articles Pattern Lab goes Django Torchbox recently released … -
Empty States - Building SaaS #83
In this episode, I returned to the onboarding flow and start to polish some of the extra pages. We filled the pages with special copy and a call to action to each page to help customers be successful. I started with the pages that displays the school years. We added a chunk of template from the onboarding process that asks the user to create a school year. I modified the template chunk to make it fit in the context of the page. -
Why is the Django Framework Suitable for Web Development?
Choosing a web development framework is challenging. But for most companies, the Django web framework is a popular choice. It is versatile, powerful, and supports Machine Learning development. A Django web development company builds scalable applications for enterprises of all shapes and sizes. The Django framework architecture... The post Why is the Django Framework Suitable for Web Development? appeared first on BoTree Technologies. -
Middleware Do You Go?
In the previous Understand Django article, we covered the built-in auth system. That article gave you a chance to see the User model, ways to login users with Django’s authentication tools, and the features that make the authorization controls work. In that topic, middleware came up as an integral component. Now we’re going to learn more about middleware and its function within a Django project. From Browser To DjangoURLs Lead The WayViews On ViewsTemplates For User InterfacesUser Interaction With FormsStore Data With ModelsAdminister All The ThingsAnatomy Of An ApplicationUser AuthenticationMiddleware Do You Go?