25 Oct 2021

feedDjango community aggregator: Community blog posts

Dear Potheads, You Can Work for the U.S. Government, Maybe

If you've used marijuana, can you still get hired by the Federal Government? Yes, but it's complicated. I'll try to explainโ€ฆ

25 Oct 2021 5:00am GMT

24 Oct 2021

feedDjango community aggregator: Community blog posts

Django tip: Redirecting straight from urls.py

<![CDATA[ Django tip: Redirecting straight from urls.py

This might be obvious to you if you are used to working with Class-based Views, but for me this was new and pretty cool.

I wanted to redirect one URL to another view and before implementing lean function view with the redirect function, I decided to look if better solution exists.. And indeed it does. Meet RedirectView.

You can use it inline in your urls.py to greatly simplify things. It can redirect either based on another route name or to any arbitrary URL.

For example here is usage from my project:

urlpatterns = [
    path('', RedirectView.as_view(pattern_name='profile-detail', permanent=True)),
]

These are URL patterns prefixed with account and I wanted the unspecified URL to redirect to account/profile which this accomplishes. The permanent settings dictate whether 301 or 302 is returned as a status code.

Instead of pattern_name you can use url attribute and redirect to anywhere. Or you can pass None there to raise status code 410, which means that this URL is no longer available.

And last attribute query_string lets us specify whether possible query string in the URL should be kept (True) or removed (False, default value).

And that's it!

This can be useful also to redirect .well-known URLs, like the one for password change or to redirect your RSS feed if you decide to move it to another URL.

]]

24 Oct 2021 11:50pm GMT

22 Oct 2021

feedDjango community aggregator: Community blog posts

Django News - DjangoCon US this Friday/Saturday - Oct 22nd 2021

News

DjangoCon US - October 22-23

The major US Django conference is online and free this year. Talks premier October 22-23, 2021, and you can watch them by joining our YouTube channel today!

djangocon.us

Python Developers Survey 2021

Please take a moment to fill out the annual Python survey that helps guide development of the language and informs the community.

jetbrains.com

Psycopg 3.0 released

A major update of the popular database adapter supporting Python 3.6-3.10 and PostgreSQL 10-14.

psycopg.org

PyPI User Feedback - Packaging - Discussions on Python.org

Feedback is requested for users of PyPI.

python.org

Sponsored Jobs

Building Intelligent Space Infrastructure

Cognitive Space is building intelligent infrastructure for the new space domain with Python at the core. We are looking for passionate Python developers in backend, dev ops, and machine learning. ๐Ÿ––

cognitivespace.com

Articles

Three more uses for functools.partial() in Django

Adam Johnson on three more ways to use functools.partial() with Django.

adamj.eu

Help users change passwords easily by adding a well-known URL for changing passwords

By redirecting requests to /.well-known/change-password to the change password URL, you can let users update their passwords easier than before.

web.dev

Django related fields and the caveats of implicit SQL INNER JOINs

A look at the Django ORM's behind-the-scenes mechanics when using related sets. Very cool.

hacksoft.io

Checking out Django in a GitHub Action

Using GitHub actions for checking out a repo.

noumenal.es

Sponsored Link

WANTED: IMPACTFUL Projects for a better world

Space Exploration. Forest fire management. Lightning strike predictions. These are three IMPACTFUL Projects (defined as projects that are impressive, purposeful, transformative and unquestionably benefit humankind) Six Feet Up has had the privilege to work on. Six Feet Up is committed to completing 10 IMPACTFUL Projects by 2025, and the company is well on its way to achieving this goal. Want to work with us? Let's talk!

sixfeetup.com

Projects

jordaneremieff/djantic

Pydantic models for Django.

github.com

groveco/django-sql-explorer: Easily share data across your company via SQL queries. From Grove Collab.

Easily share data across your company via SQL queries.

github.com

django-es/django-elasticsearch-dsl

Elastic's own elasticsearch-dsl-py is nice to work with, but sometimes it's nice to work with a more Django-friendly library which is where django-elasticsearch-dsl shines.

github.com


This RSS feed is published on https://django-news.com/. You can also subscribe via email.

22 Oct 2021 3:00pm GMT

21 Oct 2021

feedDjango community aggregator: Community blog posts

Add Service Worker to Django

Learn what is Service Worker and how to serve Service Worker in Django

21 Oct 2021 2:27pm GMT

20 Oct 2021

feedDjango community aggregator: Community blog posts

Simple Product Management Tricks

Three simple tricks product I've picked up that help me be more than completely useless when I need to wear a Product hat.

20 Oct 2021 5:00am GMT

Foss4g NL: afternoon session

(One of my summaries of a talk at the 2021 FOSS4G NL one-day conference).

Fast "BGT" dataset import with Docker - Martijn van der Struijk

(Note: the BGT (basisregistratie grootschalige topgrafie) is the Dutch database with all buildings, roads, waterways, etcin the whole country, including metadata).

You can download the BGT via an API. Previously, you could only download the entire dataset. Now there's also a "delta" endpoint that allows only changes compared to your already-downloaded version.

To handle all this, they made a "BGT loader" as a docker image. It can download the initial version + deltas. Output can be into postgis/oracle/SQLserver. They use it themselves to run it every night to update their database.

He demoed it by downloading a fresh copy of all the data for the couple of kilometers around the conference location. Easy: just a single "docker" command. Nice.

The tool stores the download-metadata (like the optional filter and the ID of the most recent change), so that a quick "download update" command is enough to update the current database contents.

Landgoed cloud - Marco Duiker

Landgoed provides foss geo services, consultancy training, etc. So one of the things they sometimes need is 20 new, nice, freshly installed work environments for students in a course... A prepared geoserver, for instance.

The new, hip thing to do is to use containers. That's nicer than preparing 20 virtual machines. Containers are much lighter than virtual machines. He mentions two containerization technologies:

  • Docker. The #1 hip thing. Everybody uses it. It is aimed at having one single application per docker. It also has drawbacks: it doesn't always behave as on a "normal" vm, you can for instance find docker-specific errors that you never see with the same app on a VM.

    Because everything is based on separate apps, you must "orchestrate" those separate apps: geoserver, database, webserver. That's the drawback and also the advantage: you can selectively scale the various components.

  • LXD aims at virtualizing a complete system. So it is more like a regular OS. So it is a bit of "a virtual machine without the drawbacks".

    It works more or less like you're used to. That can be a benefit.

He then demoed LXD. He created a container, modified it and then copied it to a fresh one. It worked pretty well.

Deploying geo webapps - Just van den Broecke

Just originally thought about a longer title: deploying geo webapps with gitops.

He showed a google image search for "osgeo installation problem" or so. Everybody started laughing. OSgeo software is very diverse. Written by many different people in different languages. You have to deal with networking and SSL certificates. Oh, and OS updates, "DLL-hell" or conflicting libraries.

Once it works, there's often a big label on it: don't touch. An ancient ubuntu 14.04 with python 2...

The solution: docker. And there's a technology you should really keep in the back of your mind for the future: kubernetes. Kubernetes is a method for managing and deploying and running your dockers. But for most people, that'll be something for later.

Anyway, docker helps a lot with packaging your applications. But then it needs to be deployed on your server(s). Something he suggests is ansible, a handy configuration-file-based way of performing tasks on servers.

He showed an example project he worked on: https://github.com/Geonovum/ogc-api-testbed

  • Github: the complete config (the one "source of truth").
  • Docker (plus docker-compose).
  • Ansible (remote deployment) via github actions (automatic workflows based on your code).

From a local dev environment, you push changes to github. Github runs ansible via automatic actions. Ansible deploys docker containers on the server. GITops, hands-off operations via github (or gitlab).

As a demo, he changed the title of the example website and it automatically got deployed to the live production website, without him doing anything on the server. Nice.

20 Oct 2021 4:00am GMT

15 Oct 2021

feedDjango community aggregator: Community blog posts

Django News - High Performance Django is Free Online - Oct 15th 2021

News

DjangoCon US is next week!

Thanks to our generous sponsors, DjangoCon US is free, online, and next week, October 22-23. If you would like to attend this year, this is also our last call for tickets.

djangocon.us

High Performance Django Is Free Online

Our friends at Lincoln Loop wrote a book, High Performance Django back in 2014, and it's now is now available for free online.

lincolnloop.com

Wagtail 2.14.2 and 2.13.5 releases!

New Wagtail 2.14.2 and 2.13.5 bug fixes.

wagtail.io

Events

FlaskCon 2021

Our friends at FlaskCon have their CFP open through October 24th.

flaskcon.com

PyCon US 2022 website is live

PyCon US 2022 will be in Salt Lake City, UT from April 27, 2022 - May 5, 2022.

pycon.org

Sponsored Jobs

Building Intelligent Space Infrastructure

Cognitive Space is building intelligent infrastructure for the new space domain with Python at the core. We are looking for passionate Python developers in backend, dev ops, and machine learning. ๐Ÿ––

cognitivespace.com

Articles

Putting Pants On: One Thing We Did Right After 5 Years with Django

A look at various improvements from moving a Django codebase to a monorepo using the Pants build framework.

github.io

Tips for debugging with print()

Five tips from Adam Johnson on making the most of out the print() function to help with debugging.

adamj.eu

Worst Case by Tim Bray

What if us-east-1 went down? If you use AWS and default to us-east-1, it might be worth re-thinking that default.

tbray.org

Tutorials

Hosting a Django Project on Heroku

A quite detailed look at all the steps involved in deploying a Django app via Heroku's free tier.

realpython.com

Podcasts

Django Chat #99 - Coverage.py with Ned Batchelder

Ned is the creator of coverage.py, a longtime organizer of the Boston Python Group, and works at EdX. We discuss what's changed in Django over the years, his thoughts on testing best practices, and managing a massive codebase.

djangochat.com

Sponsored Link

WANTED: IMPACTFUL Projects for a better world

Space Exploration. Forest fire management. Lightning strike predictions. These are three IMPACTFUL Projects (defined as projects that are impressive, purposeful, transformative and unquestionably benefit humankind) Six Feet Up has had the privilege to work on. Six Feet Up is committed to completing 10 IMPACTFUL Projects by 2025, and the company is well on its way to achieving this goal. Want to work with us? Let's talk!

sixfeetup.com

Projects

dabapps/django-log-request-id

Django middleware and log filter to attach a unique ID to every log message generated as part of a request

github.com

django-compressor/django-appconf

An app to handle configuration defaults of packaged Django apps gracefully.

github.com

pyupio/safety

Safety checks your installed dependencies for known security vulnerabilities.

github.com


This RSS feed is published on https://django-news.com/. You can also subscribe via email.

15 Oct 2021 3:00pm GMT

Accepting Crypto Payments with Django and Coinbase

This tutorial looks at how to accept crypto Payments with Django and Coinbase Commerce.

15 Oct 2021 3:28am GMT

13 Oct 2021

feedDjango community aggregator: Community blog posts

Coverage.py - Ned Batchelder

Support the Show

This podcast does not have any ads or sponsors. To support the show, please consider visiting LearnDjango.com, Button, or Django News.

13 Oct 2021 10:00pm GMT

What is your labor worth? Tech compensation in 2021

Salaries in tech are going up, and many people are looking for new jobs or reevaluating the ones they have. However, many tech workers have no idea what their labor is worth on the open market. There's a huge information asymmetry here: employers have access to detailed industry data on salaries, but workers don't. In this article, I'll share a method people can use to determine the "market rate" for their skills. I've developed this method over the last six months, as I've helped nearly 100 people figure out their worth. Feedback has been that this is pretty accurate, so I'm sharing the technique here so you can use it to determine what your labor is worth.

13 Oct 2021 5:00am GMT

Python 3.10: What's New

This article looks at the new features in Python 3.10 and how they can be implemented.

13 Oct 2021 3:28am GMT

12 Oct 2021

feedDjango community aggregator: Community blog posts

Three more uses for functools.partial() in Django

I remain convinced that Python's functools.partial() is underappreciated. Following my previous post, here are three more ways to use partial() with Django.

(For an explanation of partial() see PyDanny's post.)

1. Customizing render()

Django's render() shortcut simplifies generating an HTTP Response from rendering a template. If several views need to pass the same arguments, we can wrap the shortcut with partial() to avoid repetition.

For example, imagine we have several views that return text, rather than HTML. We could create our own render_text shortcut that calls render with the content_type argument pre-filled:

from functools import partial
from django.shortcuts import render

render_text = partial(render, content_type="text/plain")


def robots_txt(request):
    ...
    return render_text(request, "robots.txt")


def security_txt(request):
    ...
    return render_text(request, "security.txt")

(See my posts on robots.txt and security.txt.)

We can use this approach with other shortcut functions, or even HttpResponse & its subclasses.

2. transaction.on_commit() callbacks

Django's examples for transaction.on_commit() use functions, or lambdas:

from django.db import transaction

# With a function


def send_email():
    send_admin_email(
        subject="Author created",
        # ...
    )


transaction.on_commit(send_email)

# With a lambda

transaction.on_commit(
    lambda: send_admin_email(
        subject="Author created",
        # ...
    )
)

In the wild, most on_commit() callbacks only call another function with pre-filled arguments. Using lambda can make this easy, but lambda functions have their drawbacks. We can instead use partial() to bind the arguments to the function:

transaction.on_commit(
    partial(
        send_admin_email,
        subject="Author created",
        # ...
    )
)

3. Database functions

Django's database functions represent functions that will run in the database. As such, in Python they are classes, rather than functions, but this doesn't stop us from using partial() with them.

For example, to create a specialized SubStr that extracts the first character from a string, we can do:

from functools import partial

from django.db.models.functions import Substr

FirstChar = partial(Substr, pos=1, length=1)

In use, this looks just like a normal database function:

In [1]: from example.core.models import Author, FirstChar

In [2]: Author.objects.annotate(first_char=FirstChar("name")).filter(first_char="C")
Out[2]: <QuerySet [<Author: Author 'Charles Dickens' (1)>]>

For wrappers using more than one database function, we can't use partial(). Instead we can combine them with a function. For example, to take the first character and uppercase it:

from django.db.models.functions import Substr, Upper


def FirstCharUpper(expression):
    return Upper(Substr(expression, pos=1, length=1))

Even though this is a function, I like to stick to the CamelCaes naming convention so it matches the database functions.

Fin

Thank you for reading my less-than-impartial post,

-Adam

12 Oct 2021 4:00am GMT

08 Oct 2021

feedDjango community aggregator: Community blog posts

DjangoCon is Back and Free of Charge

We've waited eagerly for DjangoCon 2021 since last year's event was cancelled due to COVID-19. Not only is the event back, but it's free to attend! DjangoCon will take place virtually on October 22 and 23 - it will be unprecedented since this is the first time the conference will be virtual.

"We are very excited to allow our virtual conference to be free," said Sponsors Co-Chair Catherine Holmes who has been involved as an organizer since 2018. "In the past, the cost of tickets varied based on the cost of location, including the venue and catered meals."

But with none of that this year, the event is much more affordable to host, and the organizers decided to pass those savings on to the attendees. For comparison, tickets for the last in-person conferences in San Diego in 2018-19 were as high as $795 - so attending for free provides substantial savings. There is an option to submit a donation when you register for DjangoCon. Donations in any amount are appreciated and will go toward conference costs.

Organizers like Holmes and Sponsors Chair Dawn Wages hope the low barrier to entry will attract more attendees, especially those who may not have been able to attend in the past. Holmes and Wages worked diligently to recruit corporate sponsors to help offset the costs of the event, which was more important than ever since they're not relying on ticket sales.

Caktus is the Invitation Sponsor and Diversity and Inclusion Sponsor this year, and as always, we'll be on the lookout for sharp web dev talent. Check out our current job openings.

The Conference is Made Possible by Volunteers and More Help is Needed

DjangoCon is organized by volunteers, many of whom are members of the Django Events Foundation North America (DEFNA), a non-profit that was formed in 2015 at the request of the Django Software Foundation (DSF).

If you attend DjangoCon, they could use your help! They're looking for volunteers to assist with the DjangoCon website and are in need of attendees to hangout in the social spaces to be friendly, answer questions, and report any Code of Conduct issues.

Wages also mentioned that there's a need for Django Girls volunteers. Django Girls is a separate nonprofit supported by DEFNA and the DSF. Django Girls meetups or workshops often occur around the conference. They're holding a free programming workshop online on October 24, for marginalized genders - you must apply by October 10 to attend - or you can join the workshop as a mentor. There are other ways you can get involved with Django Girls, which are outlined on their website.

See You There!

We look forward to seeing you online at DjangoCon! Be sure to catch up with us in the virtual conference hall on October 22 and 23.

08 Oct 2021 11:02pm GMT

Django News - Django 3.2.8 and Python 3.10.0 now available! - Oct 8th 2021

News

Django bugfix release: 3.2.8

A new bugfix that fixes two issues from 3.2.7. As ever, the best security practice is to always be on the latest version of Django. Here's how to upgrade.

djangoproject.com

Python Insider: Python 3.10.0 is available

Python 3.10.0 is the newest major release of the Python programming language, and it contains many new features and optimizations.

blogspot.com

๐ŸŽƒ GitHub's guide to Hacktoberfest 2021

October is Hacktoberfest, and there are better-defined rules this year and plenty of Django and Python projects that are looking for contributions.

github.blog

Events

PyCascades 2022 is back!

The CFP (Call for Proposals) is open now and closes Sunday, October 24th. Speaker invitations will be sent out Monday, November 15th.

pretalx.com

DjangoCon US 2021

DjangoCon US 2021 will be online only on October 22-23. Make sure to grab a free ticket in advance.

djangocon.us

Sponsored Jobs

๐Ÿ’ผ Canopy is hiring software engineers!

We are seeking experienced software engineers to join our talented engineering team. We provide social impact programs evaluation & technical tools to maximize success!

canopyteam.org

Articles

Django Fellow Reports

Carlton Gibson, one of two Django Fellows, has moved his Fellow Reports to his website. These are excellent ways to catch up on Django's development quickly.

The Fellows, Carlton and Mariusz Felisiak, are contracted by the Django Software Foundation to work on Django and do the day-to-day running of the framework. They handle ticket triage, pull request review, security reports, releases, community management, and so on. These are the kind of tasks that wouldn't get done on a project the size of Django otherwise.

Django has managed monthly security/bugfix releases and major releases every eight to nine months, thanks to the Fellows.

noumenal.es

Why you can't switch to Python 3.10 just yet

Even though Python 3.10 is now available, it is unlikely every related package and release in the Python ecosystem can support it yet.

pythonspeed.com

Improving Python Dependency Management With pipx and Poetry

This article is a detailed look at using managing Python dependencies using Poetry and pipx.

cedaei.com

Tutorials

Django Celery Multiple Queues, when and how to use them

A look at when and how to use multiple Celery queues in your Django app.

appliku.com

Django REST Framework Views - ViewSets

This article takes a deep dive into Django REST Framework's most powerful view, ViewSets.

testdriven.io

Podcasts

Django Riffs #15: User Session Data

A look at sessions, a data storage technique that Django makes heavy use of for visitors to your site.

djangoriffs.com

Sponsored Link

WANTED: IMPACTFUL Projects for a better world

Space Exploration. Forest fire management. Lightning strike predictions. These are three IMPACTFUL Projects (defined as projects that are impressive, purposeful, transformative and unquestionably benefit humankind) Six Feet Up has had the privilege to work on. Six Feet Up is committed to completing 10 IMPACTFUL Projects by 2025, and the company is well on its way to achieving this goal. Want to work with us? Let's talk!

sixfeetup.com

Projects

dabapps/django-readers

django-readers is a lightweight function-oriented toolkit for better organization of business logic and efficient selection and projection of data in Django projects.

github.com

dabapps/django-zen-queries

django-zen-queries gives you direct control over database query execution in Django applications.

github.com

edx/edx-platform

The Open edX platform, the software that powers edX! This is a massive codebase supporting an equally large site. It's worth studying to see how large Django projects are organized at scale.

github.com

Django Forum

Django New Project Structure/Name

How do you structure and name your projects?

djangoproject.com

Sponsorship

๐Ÿ“ฐ Sponsor Django News

We are looking to fill out the rest of our sponsorship inventory for this year. Get in touch if you want to put your product, service, job, or company in front of over 2,181 Django developers every week. Sponsorship availability, prices, and details are available here.

django-news.com


This RSS feed is published on https://django-news.com/. You can also subscribe via email.

08 Oct 2021 3:00pm GMT

06 Oct 2021

feedDjango community aggregator: Community blog posts

How to Delegate Meeting Attendance

Wrapping up my series on delegation with an example: how to delegate meeting attendance.

06 Oct 2021 5:00am GMT

05 Oct 2021

feedDjango community aggregator: Community blog posts

Dutch python meeting: behaviour driven development - Jan-Hein Bรผhrman

(One of my summaries of a talk at a Dutch python meeting, this one in october 2021 at the Amersfoort zoo)

Behaviour driven development (BDD) is something that gets mentioned at python meetups and conferences from time to time. See this example from 2019.

What is behaviour driven development? The core point is that you specify feature behaviour. Concrete, realistic examples to create a shared understanding of how the system should behave. It is defined as a scenario:

  • Input
  • Actions
  • Outcomes

What is commonly used is the "Gherkin" language: "given .... when .... then ....". In Java, "cucumber" is a well-known library for BDD. In python you have behave.

BDD has a big benefit: you have concrete examples in an unambiguous specification. And it is in a language that can be understood by everyone from customer to programmer. An example:

Scenario: simple google search
    Given: the google homepage is displayed
    When: the user enters "panda" in the search bar
    Then: links related to "panda" are shown on the results page.

"Given" describes the initial stable state. "When" describes the action that's relevant for the scenario. "Then" describes the outcome of the action. You can add "and" statements to expand on the when or then statements.

He then showed a number of examples, as you have to make the tests executable. This means you have to tell "behave" how to translate a textual line in your scenario into a proper python test. So a "when the user selects line 2" turns into a python function:

@when("the user selects line {index:d}")
def test_impl(context):
    ...
    assert context.lines[index] == xyz

"Behave" can then use these functions to make your scenarios executable. An alternative to "behave" is pytest-bdd.

A book he recommends: Architecture patterns with python.

05 Oct 2021 4:00am GMT