Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
PyGrunn: embedding the python interpreter - Mark Boer
(One of my summaries of a talk at the 2019 PyGrunn conference). Writing scripts inside applications is often hard. Some of them luckily have an embedded version of python, but not all of them. Two important terms: extending and embedding. Lots of scientific software is made available via extending: a python wrapper. Numpy and tensorflow, for instance. The other way around is embedding: you put python inside your application. Useful for plugins, scripting. He doesn't know if jupyter notebooks are a good example of embedding, but in any case, jupyter is doing funny things with the python interpreter. CPython, which is the version of python we're talking about, consists of three parts: Bytecode compiler Python virtual machine (the one running the compiled bytecode). Python's C API, which allows other programs to call python. The C API is the opposite of python: it is hard to read and write :-) Oh, and the error messages are horrendous. But... starting python from C and sending lines to the REPL, that's quite easy. PyRun-SimpleString(). He showed a 10-line C program that reads from stdin and lets python execute it. He then expanded it to run in a separate thread. But soon his program … -
PyGrunn: data processing and visualisation of tractor data - Erik-Jan Blanksma
(One of my summaries of a talk at the 2019 PyGrunn conference). He works for Dacom, a firm that writes software to help farmers be more effective. Precision farming is a bit of a buzzword nowadays. You can get public elevation data, you can let someone fly over your fields to take measurements or a cart can do automatic ground samples. This way you can make a "prescription map" where to apply more fertilizer and where less will do. Another source of data is the equipment the farmer uses to drive over his field. As an example, the presentation looks at a potato harvester. Which route did the harvester take through the field? What was the yield (in potatoes per hectare) in all the various spots? Some tools and libraries that they use: Numpy: very efficient numerical processing. Arrays. Pandas: dataseries. Matplotlib: graph plotting library. Postgis: geographical extension to the postgres databases. Pandas is handy for reading in data, from csv for instance. It integrates nicely with matplotlib. With a one-liner you can let it create a histogram from the data. With the .describe() function, you get basic statistics about your data. Another example: a map (actually a graph, but … -
PyGrunn: advanced pytest - Òscar Vilaplana
(One of my summaries of a talk at the 2019 PyGrunn conference). Imagine being a developer being woken up at night because your latest commit broke the website. You fix the issue, run the tests of your part of the code (which passes) and push to github. That runs all the tests and it fails in a completely unrelated piece of the code. But what is happening? Is the test wrong? Is your code wrong? "3 is not 90": what does that mean? What does it mean that this fails? What is the test's promise? If a test you wrote fails, it should fail beautifully. It should tell exactly what's wrong: assert num_something == 2, "The number should match the number of added items" You can use pytest fixtures to at least make the data the test is working with clearer. You can make fixtures that work as context managers: @pytest.fixture def test_with_teardown(): thing = create_something() # setup yield thing thing.destroy() # teardown A tip: have fixtures per subsystem. Assuming you have multiple test directories, one per subsystem. Give every subsystem its own conftest.py. Different subsystems might get different fixtures even though using the same name ("product" for instance). This … -
Podcast about Evennia
I was interviewed on the (pretty grandiosely named) podcast Titans of Text the other day. In the interview, which are run by people from the MUD Coder's Guild (a great initiative!), I talk a bit about the history of Evennia, the text-based multiplayer game engine I'm working on, and go into some various technical aspects of the engine as well. Check it out and support the podcast!https://www.titansoftext.com/4 -
Pygrunn preparations
Tomorrow (friday 2019-05-10), I'm going to the nice one-day Dutch python (and friends) pygrunn conference in Groningen (NL) again. Sold out, as usual. And rightfully so. Anyway, to be honest, this blog entry is mostly about me testing my blog setup on a new laptop. I've got a linux laptop at work (which has its advantages) and since a few months I've got a second-hand macbook pro at home (because linux also has its disadvantages). But I never got around to setting up my blog software here till now. And I'm taking the macbook to the conference, so high time to get everything working :-) I'm giving a talk myself on cookiecutter, the handy tool to create initial project structures. I'm a big fan of it, so I'm glad to tell the fine folk at pygrunn about the joys and advantages of using it. I gave the talk before at work and at the Amsterdam python meetup, but that was a couple of months ago. So I invested two days to polish and re-order and rehearse the presentation again. And I updated the presentation with some more photos and videos of my model railway... -
Initial commit
Hello, world! Last month, I submitted a project proposal to Django Software Foundation for Google Summer of Code 2019. It’s titled Add Cross-DB JSONField and ArrayField, which aims to—you guessed it—bring native support for JSONField and ArrayField for all of the database backends supported by Django. Thankfully, the project has been accepted, which means I will spend my summer by coding (yay!) and documenting the feature. I decided to start this blog and make this the place for me to document my journey. Hopefully, this will be useful for me and anyone else in the future. This blog is made using Hugo (not Django, heh) with Hello Friend NG theme and deployed using Netlify. You can see the repository on GitHub. I guess that’s it for this initial commit. Stay tuned for my journey! -
Tools I Learnt About at DjangoCon Europe 2019
DjangoCon Europe 2019 was great fun. I loved meeting old and new friends, giving my talk and workshop, and learning in the other talks. The talks are now all on the YouTube Channel. If you want to read about each talk, Tobias Kunze live-blogged his notes on each. I can’t beat Tobias’ summaries. What I can present are the most interesting tools I learnt about. (Interesting to me at least!) structlog PyPI link I learnt about this in Markus Holtermann’s talk Logging Rethought 2: The Actions of Frank Taylor Jr.. Structured logging is great. I’ve previously worked with Fluentd, using it to enforce JSON structured log messages. This included parsing messages from less structured sources, such as Nginx logs, into JSON. structlog supports outputting structured log messages directly from Python, and has a similar interface to the familiar standard library logging. Also it has a cool beaver with braces as its logo. django-webpack-loader PyPI link I learnt about this in Nathan Gaberel’s talk Take the goRe out of a DjangoReact stack. Webpack is the front-end JavaScript bundler du jour. django-webpack-loader provides an easy(ish) integration between Django and Webpack. The talk is worth watching to get an idea how this works. … -
How Emerging Technologies Are Transforming Travel in 2019
Travel industry businesses are embracing technologies like the Internet of Things (IoT), artificial intelligence (AI), machine learning, virtual reality (VR), augmented reality (AR), and big data not only to provide better services to travelers but also to better understand what travelers really want. The post How Emerging Technologies Are Transforming Travel in 2019 appeared first on Distillery. -
How to make your Wagtail/Django project have good Python coding style
In this Wagtail tutorial, I will teach you how to check coding style for your Wagtail/Django project, how to fix it and how to keep it clean and concise. -
Improving My Technical Writing
I found Mikey Ariel’s talk on documentation at DjangoCon Europe 2019 “Docs or It Didn’t Happen” well timed. I’ve recently been focussing on the lifelong skill of writing, in particular for technical writing such as this blog. I want to make my writing straightforward whilst entertaining. In technology, it’s important to use clear, simple English since it’s a second language for so many of us. Misunderstandings mean bugs! The talk was one more jewel among several other resources I’ve looked at recently. Go watch it, and check out these resources, some of which Mikey mentioned. Documentarian Mikey showed us the Write the Docs definition of a documentarian: A documentarian is someone who cares about documentation and communication in the software industry, regardless of job title. I identify with this. Whilst I love to write code, I’ve come to realize without correct communication it’s useless. Hemingway App Mikey also recommended this and I’ve used it on every blog post since. It’s a style highlighter that marks complicated or unnecessary language. You can then remove it to better imitate famous adventurer-author Ernest Hemingway. (He also pioneered the standing desk.) Hemingway had a “Keep It Super Simple” (KISS) approach. There are a lot … -
My 5 Favorite Talks at DjangoCon Europe 2019
This year DjangoCon Europe happened in Copenhagen, Denmark, at a very creative and special place AFUK - Academy for Untamed Creativity. Surrounded by artistic souls, we learned more about web technologies, got to know each other at ecologic reusable disposable cups of coffee, enjoyed delicious authentic food, and socialized with Django-branded beverages. As always, there was also a party with people drinking IPA (not to be confused with API). And at the weekend Django developers were solving bugs for Django and related open-source software at the coding sprints. Here I would like to present you with the top 5 talks that I liked most of all. Django and Web Security Headers Adam Johnson (@AdamChainz) was talking about special response headers that tell browsers to treat data of the website more securely and which Django settings are responsible for those headers. Summary by rixx Docs or it didn't Happen! Mikey Ariel (@ThatDocsLady) was talking about the necessity of documentation and what to write there. Summary by rixx Pushing the ORM to its Limits Sigurd Ljødal (@sigurdlj) was talking about advanced Django ORM use cases. Summary by rixx Logging Rethought 2: The Actions of Frank Taylor Jr. Markus Holtermann (@m_holtermann) was talking … -
Sending real-time push notifications with Django, Celery and Redis
Easily improve communication with your users by delivering timely and relevant information.What’s a push notification?It’s a medium for a mobile app to deliver certain information that requires the user’s attention. Unlike pull notifications, in which the client must request information from a server, push notifications originate from the server. These cover a wide variety of use cases ranging from a flight delay alert to a social network update or a newly released feature from the app, and the list goes on.iOS push notifications. Photo by Jamie Street on UnsplashWhy am I reading this?The objective of the following post is to get a bird’s eye view of what it’s like to implement a Django based solution, using Celery and Redis, to deliver real-time push notifications upon user interaction in a mobile app through Firebase Cloud Messaging(a.k.a. FCM) or Apple Push Notification Service(a.k.a. APNS). Don’t worry, it sounds harder than it looks.Heads upThis article assumes you already have a Django environment already set up and running. If that’s not the case, you’d be better off doing that first. There’s plenty documentation out there to start from scratch.It’s not within the scope of this post to explain the setup of FCM or APNS, … -
How to Design an Effective Landing Page
Landing pages are effective only if you know exactly what and to whom you wish to sell. And while an awesome landing page will not necessarily turn visitors into buyers, it will help you find buyers among visitors. The post How to Design an Effective Landing Page appeared first on Distillery. -
Getting a Django Application to 100% Coverage
Code coverage is a simple tool for checking which lines of your application code are run by your test suite. 100% coverage is a laudable goal, as it means every line is run at least once. Coverage.py is the Python tool for measuring code coverage. Ned Batchelder has maintained it for an incredible 14 years! I like adding Coverage.py to my Django projects, like fellow Django Software Foundation member Sasha Romijn. Let’s look at how we can integrate it with a Django project, and how to get that golden 100% (even if it means ignoring some lines). Configuring Coverage.py Install coverage with pip install coverage. It includes a C extension for speed-up, it’s worth checking that this installs properly - see the installation docs for information. Then set up a configuration file for your project. The default file name is .coveragerc, but since that’s a hidden file I prefer to use the option to store the configuration in setup.cfg. This INI file was originally used only by setuptools but now many tools have the option to read their configuration from it. For Coverage.py, we put our settings there in sections prefixed with coverage:. The Run Section This is where we … -
"Create Table As Select" in Django
A discussion recently came up on django-developers mailing list about how to build the SQL query CREATE TABLE ... AS SELECT (CTAS) with Django’s ORM. This statement and its cousin INSERT ... SELECT are useful for re-shaping data inside your database, using SELECT queries. They can be useful for building aggregate tables from complicated, slow queries, as a way of imitating materialized views on databases that don’t support them. Django doesn’t support these at current, but I found it’s not hard to implement using some Django ORM internals, and have an example function below. (Support might have changed by the time you’re reading this - check the linked mailing list thread!) Example Use Case For example, you might have a widget_summary table for analytics purposes built with a SELECT from your widget table joined with flimflams. You can then regularly rebuild the table with that CTAS query. We do this in a transaction on databases with transactional DDL (PostgreSQL, SQLite). Start a transaction, drop the table, recreate it with CTAS, and commit. On databases without transactional DDL, we need a temporary table. Create the table with a new name, hot-swap it in place with the atomic RENAME, then drop the … -
Improving Page Speed with Incremental Loading
Summary: you can use django-include-by-ajax to improve the performance and usability of your website by forcing some parts of the Django website page to be loaded and shown before other parts of the page. Web browsers load and render traditional HTML pages from top to down, from left to right and as a developer you have little control over what will be shown first, second, and last. However, sometimes you need a different loading sequence to improve user experience and usability. Let's examine a couple of cases when it is advantageous to have primary content showing up immediately and secondary content loading in a moment. Case 1. Above the Fold vs. Below the Fold People want speed. 47% of visitors expect the website to be loaded in less than 2 seconds. If the website takes more than 3 seconds to show up, it's a big chance, that you will lose 40% of visitors. If you sell something on your website, every one-second delay causes 7% fewer visitors becoming buyers. One technique to improve the perception of the speed of the website is to display the visible part of the screen as soon as possible, and then load the rest of … -
How to Switch to a Custom Django User Model Mid-Project
The Django documentation recommends always starting your project with a custom user model (even if it's identical to Django's to begin with), to make it easier to customize later if you need to. But what are you supposed to do if you didn't see this when starting a project, or if you inherited a project without a custom user model and you need to add one? At Caktus, when Django first added support for a custom user model, we were still using South for migrations. Hard to believe! Nearly six years ago, I wrote a post about migrating to a custom user model that is, of course, largely obsolete now that Django has built-in support for database migrations. As such, I thought it would be helpful to put together a new post for anyone who needs to add a custom user model to their existing project on Django 2.0+. Background As of the time of this post, ticket #25313 is open in the Django ticket tracker for adding further documentation about this issue. This ticket includes some high-level steps to follow when moving to a custom user model, and I recommend familiarizing yourself with this first. As noted in the … -
How to: Run Django using Docker and Docker Compose
Read the full article -
Steaming on, eating jam
Image credit: The SmithsonianIn the last few months, development of the upcoming Evennia 0.9 has been steaming on. Evennia is, as you may know, a Python library for creating text-based multiplayer games (MUDs, MUSH etc).But it's not all backend work! There is also some sweet game-jamming going on, I get to that at the end. Evennia progress towards Python3 The regular Evennia develop branch is now running completely in Python 3. Since we are using some new features of this Python release, we will be aiming for Python 3.7 as a minimum version once Evennia 0.9 goes stable. We will also use Django 2.1 and likely Twisted 19 - so we'll be pretty much up-to-date on all our main dependencies.Now, while the release of Evennia 0.9 is still some time away (there are a bunch of regular bug fixes and minor features that I want to get in there too (see the progress here on the github 0.9 project page), it's worth to consider how much work it'll be for you to migrate and if you should wait or jump in right now.If you are new, I still recommend you use regular master branch Evennia (using Python 2.7). This is … -
Congrats to Distillery Partner PubNub on $23M in Series D Funding!
Following its $23M Series D round of funding, global data stream network (DSN) PubNub has the funding it needs to achieve its next stage of growth. The post Congrats to Distillery Partner PubNub on $23M in Series D Funding! appeared first on Distillery. -
My questions for prospective employers (Director/VP roles)
Last time I was looking for a job, I wrote up a list of questions I wanted to ask prospective employees. I just ran across the list again, and figured I’d share. I was looking for a senior management role (Director/VP-level) in Engineering or Security, so the questions are sloped in that direction. Also note that I was in a fairly strong position; I didn’t need the a job immanently. So, I was able to ask fairly direct, challenging questions. -
Family Trip to Joshua Tree
We took a family trip to Joshua Tree National Park to see the spring wildflowers in bloom. Our daughter Uma loved the fresh air and sunshine. Here, Daniel and Uma enjoy the beautiful scenery of the giant boulders. -
Family Trip to Joshua Tree
We took a family trip to Joshua Tree National Park to see the spring wildflowers in bloom. Our daughter Uma loved the fresh air and sunshine. Here, Daniel and Uma enjoy the beautiful scenery of the giant boulders. -
Family Trip to Joshua Tree
We took a family trip to Joshua Tree National Park to see the spring wildflowers in bloom. Our daughter Uma loved the fresh air and sunshine. Here, Daniel and Uma enjoy the beautiful scenery of the giant boulders. -
Avoid Memory Issues with Django’s bulk_create
When inserting a large number of objects into the database with Django, your first thought should be to use bulk_create. It is much more efficient than calling create for each object, and it generally only results in a single query. However, when dealing with tens of thousands, hundreds of thousands, or even more objects, you … Continue reading Avoid Memory Issues with Django’s bulk_create The post Avoid Memory Issues with Django’s bulk_create appeared first on concise coder.