In this article we will take a look at how you can implement a number of methods in your classes that will improve the readability of your code and make it easier to use code you have written. The methods in this post are usable when your code implements some sort of containers.
-
-
Django 1.10.3 adds important change in settings
The latest Django update, version 1.10.3 adds an important change to how Django handles the ALLOWED_HOSTS setting in your project. Previously, when running in debug mode (with DEBUG=True setting) Django ignored the ALLOWED_HOSTS setting, accepting any hostname. Since the latest update Django will validate the values in this setting regardless of the DEBUG setting. For convenience, if ALLOWED_HOSTS is empty and DEBUG=True, the following variations of localhost are allowed [‘localhost’, ‘127.0.0.1’, ‘::1’]. This change might present an issue for you if you are running a QA version of your project with the DEBUG setting or if you’re developing using production settings in the ALLOWED_HOSTS setting. Read the changelog for version 1.10.3
-
Continuous delivery with Tox and Bitbucket Pipelines
In this post we will take a look at Continuous Delivery using Tox and Bitbucket Pipelines. We will setup a basic Django project, use Tox to automate our testing and push our project to a Bitbucket repository. Then we will enable Bitbucket Pipelines to run our automated testing when we push new code to our remote repository. Important: The Bitbucket Pipelines product is currently still in Beta. It's possible to sign up for Beta access and in my experience Atlassian will quickly get you an account. What is Continuous Delivery? When we talk about Continuous Delivery it's very easy to start looking like buzzword spewing startup hipster. Don't get me wrong,…
-
Permission checking in Django views
When using the django.contrib.auth application in your project you have a number of options available for permission checking. In this recipe we will go over a number of possibilities provided by Django and offer a custom pattern you can implement. Simple testing of User objects When using function based views in your Django apps you can use the [crayon-5c6f84abdbd2b726859868-i/] decorator. This is a function decorator provided by Django that you can apply to a view function. Like the decorator name says, it tests a user object. The callable you pass the decorator should take a User object and return [crayon-5c6f84abdbd2f717309345-i/] when your test passes. Return [crayon-5c6f84abdbd30499518914-i/] from your callable to perform a…
-
Top Python links for May 2016
Every month we collect the top Python links for your enjoyment! Here is May 2016.
-
Django require authentication on all pages
This recipe gives you a useful piece of Django Middleware that requires authentication for all views of your choice.
-
Watch the PyCon 2016 talks
Stuck at home but interested in Python? Watch all talks from PyCon 2016 on the Official PyCon 2016 YouTube Channel.
-
Django version upgrades
In this guide we will take a look at what's need to upgrade a project to the new version of the Django framework.
-
Komodo IDE 9.3 vs PyCharm 5
Programmers love their tools and they love to talk about them. Plenty of questions in the Python community are similar to “What IDE should I use?”. In this lengthy article we will take a good look at both PyCharm and Komodo, two well known IDE’s available today. In this Python IDE comparison we will take a look at the latest versions of PyCharm and Komodo IDE. Jetbrains release PyCharm 5 this week and ActiveState followed with version 9.3 of their Komodo IDE. Both releases are quite important since Python 3.5 is now fully supported and both contain a number of cool new features.
-
Tuple Unpacking
Something few beginning Python programmers know about is tuple unpacking. This allows you to do fun stuff like returning multiple values from a function. Everyone knows how to create a tuple, right? [crayon-5c6f84abdc2fb689889312/] Well using tuple unpacking, you can get all values from a tuple in one expression and store them in their own variables. [crayon-5c6f84abdc2fe167233305/] This allows you to do fun stuff like return multiple values from a function, by returning them as a tuple. After getting the return value from a function you simply unpack the tuple. [crayon-5c6f84abdc300989439593/] And unpacking the returned tuple in one simple expression: [crayon-5c6f84abdc301141658768/]