Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Why You Should Pin Your Dependencies by My Mistakes
Have you ever been bitten by not pinning your dependencies in your django project? If not be glad, and come learn from my problems. Pinning your dependencies is important to solve future unknown issues, better the devil you know and all that. In this weeks video I talk about 3 times I had issues. They are either not pinning my dependencies, a weird edge case with pinning and python, and not really understanding what I was doing with pinned dependencies. Why You Should Pin Your Dependencies -
How to Create User Sign Up View
In this tutorial I will cover a few strategies to create Django user sign up/registration. Usually I implement it from scratch. You will see it’s very straightforward. For the examples I will use an empty Django project named mysite. Inside the mysite folder I created an app named core. So every time you see mysite and/or core, change to the suitable project name and app name. A brief summary of what you are going to find here: Basic Sign Up Sign Up With Extra Fields Sign Up With Profile Model Sign Up With Confirmation Mail Basic Sign Up The most simple way to implement a user sign up is by using the UserCreationForm as it is. This strategy is suitable in case you are using the default Django user, using username to authenticate and is interested only in setting the username and password upon sign up. urls.py from django.conf.urls import url from mysite.core import views as core_views urlpatterns = [ ... url(r'^signup/$', core_views.signup, name='signup'), ] views.py from django.contrib.auth import login, authenticate from django.contrib.auth.forms import UserCreationForm from django.shortcuts import render, redirect def signup(request): if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): form.save() username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') user = … -
Caktus Attends Wagtail CMS Sprint in Reykjavik
Caktus CEO Tobias McNulty and Sales Engineer David Ray recently had the opportunity to attend a development sprint for the Wagtail Content Management System (CMS) in Reykjavik, Iceland. The two-day software development sprint attracted 15 attendees hailing from a total of 5 countries across North America and Europe. -
HTML Template to PDF in Django
** Still in Development ** ... -
Create a Blank Django Project
A easy to use guide for creati... -
History of the URL, or why you are confused by serving many domains with a single server
I’ve noticed that many people attempting to deploy Django have trouble understanding how a single web server installation can serve many domains. One reason is that words matter. What Apache calls a “virtual host” is exactly what nginx calls a “server” and what HTTP calls a “host”. It is neither a host (let alone a virtual one) nor a server; it’s a domain. Let’s clear this up. The first version of the HyperText Transfer Protocol was very simple. If your browser wanted to visit page http://djangodeployment.com/apage, it would connect to the server djangodeployment.com, port 80, and after the TCP connection was established it would send this line to the server, terminated with a newline: GET /apage The server would then respond with the content of that page and close the connection. The content of the page was usually something like this: <html> <head> <title>Hello</title> </head> <body> <p>hello, world</p> </body> </html> In that era, a single computer could not distinguish different domains in the request. Whether you visited http://djangodeployment.com/apage or http://71.19.145.109/apage you’d get the same response. This is because the whole syntax of the URL, protocol://host[:port]/path, assumed you would get a path from a server. In that context, “host” is synonymous … -
Different types of testing in Django
Testing is always one of those topics that can be interesting to talk about. There are a lot of different opinions on testing so it can be fun. Django comes with some great tools for testing, so this week we will talk a little bit about the different types of tests. Then expand on that with how that relates to Django. I also present to you a new type of test at the end of the video that I have been using, special thanks to a co-worker for coming up with the idea. It is really specific to django, and I haven't heard of others doing it. Different Types of Tests with Django -
Podcasttime.io - How Much Time Do Your Podcasts Take To Listen To?
It's a web app where you search and find the podcasts *you* listen to. It then gives you a break down how much time that requires to keep up per day, per week and per month. -
Django - migrating from function based views to class based views
The single most significant advantage in Django class-based views is inheritance. On a large project, it's likely that we will have lots of similar views. Instead of writing the repeated code we can simply have our views inherit from a base view. Also, Django ships with a collection of generic view classes that can be used to do some of the most common tasks. 1. Template View Function based view urls.py from django.conf.urls import url from . import views urlpatterns = [ url(r'^about-us/$', views.about_us, name="about_us"), ] views.py from django.shortcuts import render def about_us(request): return render(request, 'templates/contact.html') Class based view urls.py from django.conf.urls import url from .views import AboutUs urlpatterns = [ url(r'^about-us/$', AboutUs.as_view(), name="about_us"), ] views.py from django.views.generic import TemplateView class AboutUs(TemplateView): template_name = "templates/about.html" or we can directly write it in "urls.py" urls.py from django.conf.urls import url from django.views.generic import TemplateView urlpatterns = [ url(r'^about-us/$', TemplateView.as_view(template_name= "templates/about.html"), name="about_us"), ] 2. Detail View Function based view urls.py from django.conf.urls import url from . … -
Set Up Travis CI For Django project
Travis CI is a continuous integration service used to build and test applications hosted on GitHub. Travis CI supports integration with other tools such as coverage analyzers. Why use Travis? Travis CI runs your program's tests every time you commit to GitHub. you can easily discover your code breaks. setting up Travis-ci is very easy. To run tests in Travis you have to create ".travis.yml" file in root directory. .travis.yml file for Django application. language: python # => 1 python: # => 2 - "2.6" - "2.7" services: # => 3 - mysql env: # => 4 -DJANGO=1.8 DB=mysql install: # => 5 - pip install -r requirements.txt before_script: # => 6 - mysql -e 'create database test;' -u root script: # => 7 - python manage.py test Explanation for above comments: 1. By defining "language: python" application is developed in python language. 2. Test your application in multiple versions of python by defining versions in python hook settings 3. Define services required for your application ex: elastic … -
Deploying Your Django app on Heroku
Heroku is a cloud application platform it's a new way of building and deploying web apps, Which makes easy to host your application in the cloud with a simple git push command. Heroku supports several programming languages like(Python, Java, PHP) Install the Heroku Toolbelt: The first thing you need to do is to install the Heroku toolbelt. In order to interact with heroku service, the toolbelt is best command line software. Here you can find out the Heroku toolbelt installation for Debian/Ubuntu, Run this from your terminal: wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh In the below link you need to select your required operating system(Download Heroku Toolbelt for..) for installing heroku toolbelt in your system. And then you can proceed to install. Please click here to install Heroku ToolBelt After successfully installation of toolbelt, you can use the heroku command from your terminal. heroku login You will prompt to provide heroku credentials(Email and password), once you have authenticated you can access both heroku and git commands. Create your heroku app: The following command is used to create an app heroku create your-app-name Here 'your-app-name' should be unique, heroku will generate default app-name if you won't specify any app-name. For creating remote … -
Django Unit Test cases with Forms and Views
Test Cases For Forms, Views In this post, we’ll see how to write unit test cases for any project. Having tests for any project will helps you to find bugs. If any of the function breaks, you will know about it. Its easier to debug code line by line. Unit Tests: Unit Tests are isolated tests that test one specific function. Test Case: A test case is executing set of features for your Application. Proper development of test cases finds problems in your functionality of an Application. Test suite: A test suite is a collection of test cases. It is used to aggregate tests that should be executed together. In general, tests result in either a Success (expected results), Failure (unexpected results), or an error. While writting test cases, not only testing for the expected results but also need to test how good your code handles for unexpected results. Testing the Forms: Consider a Form: from django import forms from .models import * class UserForm(forms.ModelForm): class Meta: model = User fields = ('email', 'password', 'first_name', 'phone') setUp(): The setUp() methods allows to define instructions which will be executed before and after … -
Angular 2 Setup Guide
# This guide is still being de... -
Srvup 2 is here
The future of education will l... -
Typescript Setup Guide
** This guide is still being d... -
How To Export Django Model Data Along With Its Parent Model Data via dumpdata Command
Django dumpdata command lets us export model objects as fixtures and store them in json / xml formats. All is good and works fine until a moment when your model is a children of a concrete model and shares two db tables (one for parent another is for model). If you ... Read now -
Activate, Reactivate, Deactivate your Virtualenv
Here's a quick guide to activa... -
Django PositionField
Sometimes you need ordering in... -
5 Reasons to Use Class Based Views
Anytime anyone brings up Class Based Views, generic and otherwise, it is similar to the Vim vs Emacs debate. So lets pile on a bit more. But not really. In actuality, I feel like there are good, solid, and legitimate reasons to use Class Based Views which get passed over in the middle of arguments. In this weeks topic I talk about 5 of those reasons I think people should use Class Based Views. In reality there are more, but I wanted to keep the video short'ish. 5 Reasons to Use Class Based Views -
How to Implement Case-Insensitive Username
Inspired by a discussion in the How to Extend Django User Model comments, I decided to compile a few options on how to implement a case insensitive authentication using the built in Django User. Thanks to Paul Spiteri for bringing up the question and also to provide a possible solution! Option 1: Custom Authentication Backend Please note that there is a small difference in the implementation between Django 1.10 and 1.11, as from 1.11 the authenticate method receives a request object. Django Version 1.10.x Or Below If your application is already up and running and you can’t afford to customize the Django User model, this is the less intrusive way. Create a python module named backends.py anywhere in your project and add the following snippet: backends.py from django.contrib.auth import get_user_model from django.contrib.auth.backends import ModelBackend class CaseInsensitiveModelBackend(ModelBackend): def authenticate(self, username=None, password=None, **kwargs): UserModel = get_user_model() if username is None: username = kwargs.get(UserModel.USERNAME_FIELD) try: case_insensitive_username_field = '{}__iexact'.format(UserModel.USERNAME_FIELD) user = UserModel._default_manager.get(**{case_insensitive_username_field: username}) except UserModel.DoesNotExist: # Run the default password hasher once to reduce the timing # difference between an existing and a non-existing user (#20760). UserModel().set_password(password) else: if user.check_password(password) and self.user_can_authenticate(user): return user Now switch the authentication backend in the settings.py module: settings.py … -
Django Dynamic Formsets
Django forms are one of the most important parts of the stack: they enable us to write declarative code that will validate user input, and ensure we protect ourselves from malicious input. Formsets are an extension of this: they deal with a set of homogeous forms, and will ensure that all of the forms are valid independently (and possibly do some inter-form validation, but that's a topic for a later day). The Django Admin contains an implementation of a dynamic formset: that is, it handles adding and removing forms from a formset, and maintains the management for accordingly. This post details an alternative implementation. *** A Formset contains a Form (and has zero or more instances of that Form). It also contains a "Management Form", which has metadata about the formset: the number of instances of the form that were provided initially, the number that were submitted by the user, and the maximum number of forms that should be accepted. A Formset has a "prefix", which is prepended to each element within the management form: {% highlight html %} {% endhighlight %} Each Form within the Formset uses the prefix, plus it's index within the list of forms. For instance, … -
News items from the new year
The last few months have been mostly occupied with fixing bugs and straightening out usage quirks as more and more people take Evennia through its paces.Webclient progressOne of our contributors, mewser/titeuf87 has put in work on implementing part of our roadmap for the webclient. In the first merged batch, the client now has an option window for adjusting and saving settings. This is an important first step towards expanding the client's functionality. Other features is showing help in an (optional) popup window and to report window activity by popup and/or sound. The goal for the future is to allow the user or developer to split the client window into panes to which they can then direct various output from the server as they please It's early days still but some of the example designs being discussed can be found in the wiki webclient brainstorm (see the title image of this blog for one of the mockups). New server stuffLast year saw the death of our old demo server on horizondark.com, luckily the new one at silvren.com has worked out fine with no hickups. As part of setting that up, we also got together a more proper list of recommended … -
A Unique Slug Generator for Django
Using the [Random String Gener... -
Random String Generator in Python
Sometimes you need a random st... -
How reliable is my virtual server?
Digital Ocean advertises its services as “cloud computing”, and sometimes refers to its virtual servers, its “droplets” that is, as “cloud servers”. Reader Chris Pantazis asked me if this means it has less downtime than a provider that doesn’t advertise them in this way. The answer is that “cloud” doesn’t mean anything at all. In this post I explain how virtual server providers minimize downtime. I assume you understand clearly what a “virtual machine” is. If you don’t, download VirtualBox on your computer, create a virtual machine, and run it; the best way to grasp the concept is to see it in action. We often use virtual machines as servers, in which case we also call them virtual servers. Virtual machines run inside physical machines. Depending on the capacity (mostly the RAM and CPU) of the physical machine and the size of the virtual machines, a physical machine can run from a handful to a few hundreds of virtual machines. Virtual machine providers like Digital Ocean have many computers stacked on a rack like the one on the picture on the right, and a data centre has many racks, as seen in the picture on the left. The virtual machine …