Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django App Structure
To make your individual Django... -
Syncdb is ... gone?
Yup `python manage.py syncdb` ... -
A Fantastic Ted Talk
This is by far one of the most... -
Everything coming in 2017
Topics</... -
*args and **kwargs
So when you write any given fu... -
Testing Email in Django with send_mail
Sometimes you need to test tha... -
Which Version to Use?
When you watch or read tutoria... -
New URL Structure for Django
Django 1.10 has changed the re... -
post_save vs pre_save vs override save method
Which is better ... `post_save... -
TemplateDoesNotExist error
I see this error come up a lot... -
Hats off to you...
CFE Community! Hats off to ... -
Transcoding with AWS- part five
This is the last blog post in this series - the only thing that has to be done is telling the user that file he or she uploads is processed. It will be done by writing custom message application. Tabel of Contents: How message application should work Implementation in django Other blog posts in this series How message application should work From previous post I know that the last point of my application flow is to inform user that file is transcoded and ready to download. To do such thing I have to display message on every webpage that current user is. This message should have information about which file was processed. First I wanted to do this with existing django messaging framework but as it turns out is works only with request. As I decided to show message for different users as long as they dismiss this information I had to write my own small application. Implementation in django In my newly created application I created following model: from django.db import models from django.contrib.auth.models import User class Message(models.Model): text = models.CharField(max_length=250) read = models.BooleanField(default=False) def __str__(self): return self.text I decided to display my message only when it wasn't read. … -
Transcoding with AWS- part five
This is the last blog post in this series - the only thing that has to be done is telling the user that file he or she uploads is processed. It will be done by writing custom message application. Tabel of Contents: How message application should work Implementation in django Other … -
Integrate Django-Oscar-Accounts with Django-Oscar
Django Oscar Accounts is a package that provides the ability to manage accounts with fully managed account functionality to use with Django Oscar. * Django Oscar Accounts provides managed accounts using double-entry bookkeeping. * In this package every transaction is recorded twice(once for the source account and once for the destination account) by using double-entry bookkeeping. This make sure that books always balance and there exist full record of all transactions. Features - A user can have multiple accounts An account can be created with - no users assigned, a single primary user assigned or set of users can be assigned An account consists of start date and end date to restrict its usage in a limited time, also it can be restricted so that it can only be used to pay for a range of products. An account has a credit limit, by default it will be zero. Installation - * Install using pip: pip install django-oscar-accounts * Next, add "oscar_accounts" to INSTALLED_APPS in settings file. * After this apply migrations with "manage.py migrate oscar_accounts" command. This will create the appropriate database tables. * Next use "manage.py oscar_accounts_init" command to create core accounts and account-types. The names of these … -
Ship It Day Q1 2017
Last Friday, Caktus set aside client projects for our regular quarterly ShipIt Day. From gerrymandered districts to RPython and meetup planning, the team started off 2017 with another great ShipIt. Books for the Caktus Library Liza uses Delicious Library to track books in the Caktus Library. However, the tracking of books isn't visible to the team, so Scott used the FTP export feature of Delicious Library to serve the content on our local network. Scott dockerized Caddy and deployed it to our local Dokku PaaS platform and serves it over HTTPS, allowing the team to see the status of the Caktus Library. Property-based testing with Hypothesis Vinod researched using property-based testing in Python. Traditionally it's more used with functional programming languages, but Hypothesis brings the concept to Python. He also learned about new Django features, including testing optimizations introduced with setupTestData. Caktus Wagtail Demo with Docker and AWS David looked into migrating a Heroku-based Wagtail deployment to a container-driven deployment using Amazon Web Services (AWS) and Docker. Utilizing Tobias' AWS Container Basics isolated Elastic Container Service stack, David created a Dockerfile for Wagtail and deployed it to AWS. Down the road, he'd like to more easily debug performance issues and … -
How I Deploy Django Day-to-Day
There are a lot of ways to deploy Django so I think it is one of those topics people are really curious about how other people do it. Generally, in all deploys you need to get the latest code, run migrations, collect your static files and restart web server processes. How yo do those steps, that is the interesting part. In todays video I go over How I deploy Django day to day, followed by some other ways I have done it. This is definitely a topic you can make as easy or complicated as you want. Here is the link again: https://www.youtube.com/watch?v=43lIXCPMw_8?vq=hd720 -
Why does Django not email me the 500 internal server error?
You’ve set your EMAIL_* settings correctly, and when you try to send emails with django.core.mail.sendmail() it works. However, Django still does not send you internal server errors. Why? The sender’s email address matters SERVER_EMAIL is the email address from which emails with error messages appear to come from. It is set in the “From:” field of the email. The default is “root@localhost”, and while “root” is OK, “localhost” is not, and some mail servers may refuse the email. The domain name where your Django application runs is usually OK, but if this doesn’t work you can use any other valid domain. The domain of your email address should work properly. → Set SERVER_EMAIL → When testing with django.core.mail.sendmail(), use the same sender email address as the one you’ve specified in SERVER_EMAIL. The recipient’s email address matters Because of spam, mail servers are often very picky about which emails they will accept. It’s possible that even if your smarthost accepts the email, the next mail server may refuse it. For example, I made some experiments using EMAIL_HOST = 'mail.runbox.com' and this command: send_mail('Hello', 'hello, world', 'noreply@example.com', ['anthony@itia.ntua.gr']) In that case, Runbox accepted the email and subsequently attempted to deliver it to … -
New Django Admin with DRF and EmberJS... What are the news?
A couple months ago, I published a post titled "Yes I want a new admin". Now that more than a few weeks have gone by, I want to bring you up to speed on the progress. In the original post, it was mentioned that, in order to achieve this goal, several libraries would be needed and that some of these libraries were already published. Among them were DRF-auto-endpoint and djember-model. During Django Under The Hood's sprints, we got together with several people interested by the concepts of those two libraries, merged them in a signle library (DRF-schema-adapter) and added some functionalities. Other than being a merge of the two "old" libraries DRF-schema-adapter also brings the concept of adapters which make it possible to use the same library for different frontends. DRF-schema-adapter pursues 3 main goals: Making it as easy, fast and straight-forward to define an API endpoint as it would be to generate a ModelAdmin class. Letting developpers be DRYer by generating frontend code (models, resources, stores, ...) based on your DRF endpoints. Providing enough information to the client to be entirely dynamic. Although there are still some improvements planned for the library, all 3 of these goals have been … -
Using Python weasyprint generate HTML to PDF in django
In most of the web development projects you might want to automate file generation, like for example placeorder confirmation receipts, payment receipts, that can be based on a template you are using. The library we will be using is Weasyprint. WeasyPrint is to combine multiple pieces of information into an HTML template and then converting it to a PDF document. The supported version are Python 2.7, 3.3+ WeasyPrint has lot of dependencies, So this can be install it with pip. pip install Weasyprint Once you have installed WeasyPrint, you should have a weasyprint executable. This can be as simple: weasyprint --version This will Print WeasyPrint's version number you have installed. weasyprint <Your_Website_URL> <Your_path_to_save_this_PDF> Eg: weasyprint http://samplewebsite.com ./test.pdf Here i have converted "http://samplewebsite.com" site to an test.pdf. Let we write sample PDF Generation: from weasyprint import HTML, CSS HTML('http://samplewebsite.com/').write_pdf('/localdirectory/test.pdf', stylesheets=[CSS(string='body { font-size: 10px }')]) This will also converts the page in to PDF, Here the change is we are writting custom stylesheet(CSS) for the body to change the font size using the "string" argument. You can also pass the CSS File, This can be done using: from django.conf import settings … -
Transcoding with AWS- part four
As I have my transcoder up and running now it's time to let user know that their uploaded files were transcoded. To this occasion I will use AWS SNS service which allows me to send notification about completion of transcode job. Table of Contents: Setting up AWS SNS to work with AWS Transcoder Receiving notifications from SNS service in Django Other blog posts in this series Setting up AWS SNS to work with AWS Transcoder After logging to AWS console and selecting SNS I have to create a topic: Topic is endpoint for other application in AWS to send their notifications. For my case I have to change it in AWS Transcoder pipeline settings: Last thing I have to do was to create subscription for topic created above. They are a lot of types of subscription that you can find in SNS settings but I will be using HTTP request. Receiving notifications from SNS service in Django The flow of application will look like this: User upload a file File is sent to S3 Transcode job is fired after uploading form view After transcode completion AWS transcoder sends SNS notification This notification is taken by SNS subscription and send to … -
Transcoding with AWS- part four
As I have my transcoder up and running now it's time to let user know that their uploaded files were transcoded. To this occasion I will use AWS SNS service which allows me to send notification about completion of transcode job. Table of Contents: Setting up AWS SNS to work … -
New year, new Python: Python 3.6
Python 3.6 was released in the tail end of 2016. Read on for a few highlights from this release. New module: secrets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Python 3.6 introduces a new module in the standard library called secrets. While the random module has long existed to provide us with pseudo-random numbers suitable for applications like modeling and simulation, these were not "cryptographically random" and not suitable for use in cryptography. secrets fills this gap, providing a cryptographically strong method to, for instance, create a new, random password or a secure token. New method for string interpolation Python previously had several methods for string interpolation, but the most commonly used was str.format(). Let’s look at how this used to be done. Assuming 2 existing variables, name and cookies_eaten, str.format() could look like this: "{0} ate {1} cookies".format(name, cookies_eaten) Or this: "{name} ate {cookies_eaten} cookies".format(name=name, cookies_eaten=cookies_eaten) Now, with the new f-strings, the variable names can be placed right into the string without the extra length of the format parameters: f"{name} ate {cookies_eaten} cookies" This provides a much more pythonic way of formatting strings, making the resulting code both simpler and more readable. Underscores in numerals While it doesn’t come up often, it has long been … -
Which components should I use in production?
This is the last in a series of posts about whether you should choose Ubuntu or Windows, Gunicorn or uWSGI, MySQL or PostgreSQL, and Apache or nginx. I bring it altogether. The image illustrates the components I propose for a start. […]The post Which components should I use in production? appeared first on Django deployment. -
5 Reasons I don't think you shold use the django admin
Have you ever needed to quickly modify data or look it up. But while the task is simple the entire process of changing one value frustrates you? Well, this is very common to me, bad UX is annoying. I quite often have to either lookup, or edit, two disparate, yet related pieces of data, and sometimes it is an exercise in frustration. An all to common occurrence is I just needed to check the edit history of a "Company" our database. This is a simple process, go to the admin find the Company model, do a search and you have your answer. Except, it isn't that easy in reality. Lets run through what really happened. I went to "http://superawesomesite.com/admin/" and logged in. I then looked at how my model options extended well below the fold of my browser so I had to scroll. No problem I'll just hit "ctrl+f" and search for it. WTF!!! where is my company model? I then proceed to scroll down and finally find it only to remember it was pluralized. If I had searched for "Companies" I would have been good to go, grrrrr. I click into and see the list of companies available to … -
Event sourcing in Django
Django comes with "batteries included" to make CRUD (create, read, update, delete) operations easy. It's nice that the CR part (create and read) of CRUD is so easy, but have you ever paused to think about the UD part (update and delete)? Let's look at delete. All you need to do is this: ReallyImportantModel.objects.get(id=32).delete() # gone from the database forever Just one line, and your data is gone forever. It can be done accidentally. Or you can be do it deliberately, only to later realise that your old data is valuable too. Now what about updating? Updating is deleting in disguise. When you update, you're deleting the old data and replacing it with something new. It's still deletion. important = ReallyImportantModel.object.get(id=32) important.update(data={'new_data': 'This is new data'}) # OLD DATA GONE FOREVER Okay, but why do we care? Let's say we want to know the state of ReallyImportantModel 6 months ago. Oh that's right, you've deleted it, so you can't get it back. Well, that's not exactly true -- you can recreate your data from backups (if you don't backup your database, stop reading right now and fix that immediately). But that's clumsy. So by only storing the current state of …