Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Multiple File Image/Upload with Django, Angular 7 and FormData
In the previous tutorial we have seen how to implement file uploading in Django and Angular 7. In this tutorial, we'll see how to implement multiple file uploading. It's recommended that you start from the previous tutorial to see detailed steps of how to create a django project, how to install Angular CLI and generate a new Angular 7 project along with services and components as we won't cover those basics in this part. If you don't want to follow the steps from the previous part, you first need to get the project we've built. Open a new terminal and run the following command: $ git clone https://github.com/techiediaries/django-angular-file-upload-example.git Next, navigate inside the project's folder and install the npm dependencies using the following command: $ cd django-angular-file-upload-example $ npm install Next, start the development server using: $ ng serve Your Angular application will be available from the 127.0.0.1:4200 address. Open a new terminal window and create a virtual environment using the following command: $ python3 -m venv .env Next, activate the virtual environment using: $ source .env/bin/activate Next, navigate to the backend project and install the Python packages using: $ cd django-angular-file-upload-example/backend $ pip install -r requirements.txt Finally, start the development … -
Django REST Framework Image File Upload Tutorial & Example [FormData & Angular 7 UI]
Throughout this tutorial, we'll see how you can implement file upload in Django and Django REST Framework with a step by step example. Our application will expose an /upload endpoint that accepts POST requests that contain the file posted with a multipart/form-data content type using FormData. For the frontend, we'll be using Angular 7 to create a simple interface that allows the user to select a file and upload it to the server via a POST request and FormData. These tutorials is divided in two parts: In the first part we'll create the Django application and make a REST API client to make sure it properly work. In the second part, we'll proceed to create a frontend with Angular 7. Let's get started! Prerequisites For this tutorial, you will need to have a few prerequisites such as: Python and pip installed on your system. We'll be using Python 3.7, Familiarity with Python and Django. Node.js and NPM installed on your system. These are required by Angular CLI. Familiarity with TypeScript. Creating a Virtual Environment & Installing Django If you have Python and pip installed on your system, let's get started by creating a new virtual environment for our project's dependencies. … -
Why We Love Wagtail (and You Should, Too)
New clients regularly ask us if we build WordPress sites. When we dig deeper, we generally learn that they’re looking for a user-friendly content management system (CMS) that will allow them to effortlessly publish and curate their site content. As we’ve written about previously, WordPress can be a good fit for simple sites. However, the majority of our clients need a more robust technical solution with customizable content management tools. For the Python-driven web applications that we develop, we love to work with Wagtail. What is Wagtail? Wagtail is a Python-driven CMS built on the Django web framework. It has all the features you’d expect from a quality CMS: intuitive navigation and architecture user-friendly content editing tools painless image uploading and editing capabilities straightforward and rapid installation What Makes Wagtail Different? From the user’s perspective, Wagtail’s content editor is what sets it apart, and it’s why we really love it. Most content management systems use a single WYSIWYG (“what you see is what you get”) HTML editor for page content. While Wagtail includes a WYSIWYG editor — the RichTextField — it also has the Streamfield, which provides an interface that allows you to create and intermix custom content modules, each … -
DjangoChat Podcast
Launching a new podcast with Carlton Gibson focused on Django. -
The Benefits of Design Systems: Cutting Costs and Creating Competitive Advantage
A design system is far more than a UI kit. A design system is a continuously evolving single source of truth that establishes rules of visual narration and interaction. It must be comprehensive, combining components, behaviors, and branding. The post The Benefits of Design Systems: Cutting Costs and Creating Competitive Advantage appeared first on Distillery. -
Contributing to classiness (in Django)
A couple weeks ago I ran a poll on Twitter asking people whether they’d ever used, or considered using, the contribute_to_class() method to write something that attaches to or hooks into a Django ORM model class, and if so what their thoughts were. There was also a “don’t know what that is” option, which won by a large margin, and I promised I’d provide an explanation. Unfortunately, that was around the time I suffered a kitchen ... Read full entry -
My involvement in the Python community
An article about me and my involvement in the Python community (mainly Django) as a Free Software developer, GNU/Linux user and tech conference speaker. -
My involvement in the Python community
An article about me and my involvement in the Python community (mainly Django) as a Free Software developer, GNU/Linux user and tech conference speaker. -
Django: Recommended Reading
Pictured: Our library of reference books at Caktus cover topics including Django and Python, as well as project management and Agile methodologies. At Caktus, we believe in continued learning (and teaching). It's important to read up on the latest industry trends and technologies to stay current in order to address our clients' challenges. We even maintain a library in our office for staff use, and we add references frequently. Our team enjoys sharing what they've learned by contributing to online resources, such as the Django Documentation and the Mozilla Developer Network Web Docs. Below is a list (in alphabetical order) of the books, blogs, and other documents that we’ve found to be the most accurate, helpful, and practical for Django development. Django Documentation Authors: Various Recommended by Developer Dmitriy Chukhin Overview: When Dmitriy first began learning about Django, he went through the official Django tutorial. Then, as a developer, he read through other pieces of documentation that are relevant to his work. A Valuable Lesson: Dmitriy learned that detailed documentation makes working with a framework significantly easier than trying to figure it out on his own or from other developers’ posts about their errors. The documentation is readable, uses understandable … -
Django Tips & Tricks #12 - Automatically Set CSRF Token in Postman
Introduction Django has inbuilt CSRF protection mechanism for requests via unsafe methods to prevent Cross Site Request Forgeries. When CSRF protection is enabled on AJAX POST methods, X-CSRFToken header should be sent in the request. Postman is one of the widely used tool for testing APIs. In this article, we will see how to set csrf token and update it automatically in Postman. CSRF Token In Postman Django sets csrftoken cookie on login. After logging in, we can see the csrf token from cookies in the Postman. We can grab this token and set it in headers manually. But this token has to be manually changed when it expires. This process becomes tedious to do it on an expiration basis. Instead, we can use Postman scripting feature to extract token from cookie and set it to an environment variable. In Test section of postman, add these lines. var xsrfCookie = postman.getResponseCookie("csrftoken"); postman.setEnvironmentVariable('csrftoken', xsrfCookie.value); This extracts csrf token and sets it to an evironment variable called csrftoken in the current environment. Now in our requests, we can use this variable to set the header. When the token expires, we just need to login again and csrf token gets updated automatically. Conclusion … -
Django Tips & Tricks #12 - Automatically Set CSRF Token in Postman
Introduction Django has inbuilt CSRF protection mechanism for requests via unsafe methods to prevent Cross Site Request Forgeries. When CSRF protection is enabled on AJAX POST methods, X-CSRFToken header should be sent in the request. Postman is one of the widely used tool for testing APIs. In this article, we will see how to set csrf token and update it automatically in Postman. CSRF Token In Postman Django sets csrftoken cookie on login. After logging in, we can see the csrf token from cookies in the Postman. We can grab this token and set it in headers manually. But this token has to be manually changed when it expires. This process becomes tedious to do it on an expiration basis. Instead, we can use Postman scripting feature to extract token from cookie and set it to an environment variable. In Test section of postman, add these lines. var xsrfCookie = postman.getResponseCookie("csrftoken"); postman.setEnvironmentVariable('csrftoken', xsrfCookie.value); This extracts csrf token and sets it to an evironment variable called csrftoken in the current environment. Now in our requests, we can use this variable to set the header. When the token expires, we just need to login again and csrf token gets updated automatically. Conclusion … -
How 5G Network Development Will Go Global In 2019
The next generation of mobile internet connection is just around the corner. Carriers, manufacturers, vendors and companies are preparing for the introduction of 5G. If you don’t know what is 5G already, it is the 5th generation of mobile networking technology that promises to bring even faster and more reliable wireless connections across the globe. With testing and small market launches already in progress, we expect to see rapid adoption of the 5G network in 2019. Here are the anticipated 5G network developments coming up in the next year. The post How 5G Network Development Will Go Global In 2019 appeared first on Distillery. -
Sorry I seemed to have missed this!
Sorry I seemed to have missed this! The @next label is used for anything that doesnt have a due date, but can be worked on anytime. That way my filters have a list of things that are due that day (@waiting-for & today) as well as items I can start working on anytime (@next) -
You are right, if I mentioned @wait-for I meant @waiting-for, Ill look over the article and see if…
You are right, if I mentioned @wait-for I meant @waiting-for, Ill look over the article and see if I can fix that issue.The @next label is used for anything that doesnt have a due date, but can be worked on anytime. That way my filters have a list of things that are due that day (@waiting-for & today) as well as items I can start working on anytime (@next) -
Django ORM optimization story on selecting the least possible
This an optimization story that should not surprise anyone using the Django ORM. But I thought I'd share because I have numbers now! The origin of this came from a real requirement. For a given parent model, I'd like to extract the value of the name column of all its child models, and the turn all these name strings into 1 MD5 checksum string. Variants The first attempted looked like this: artist = Artist.objects.get(name="Bad Religion") names = [] for song in Song.objects.filter(artist=artist): names.append(song.name) return hashlib.md5("".join(names).encode("utf-8")).hexdigest() The SQL used to generate this is as follows: SELECT "main_song"."id", "main_song"."artist_id", "main_song"."name", "main_song"."text", "main_song"."language", "main_song"."key_phrases", "main_song"."popularity", "main_song"."text_length", "main_song"."metadata", "main_song"."created", "main_song"."modified", "main_song"."has_lastfm_listeners", "main_song"."has_spotify_popularity" FROM "main_song" WHERE "main_song"."artist_id" = 22729; Clearly, I don't need anything but just the name column, version 2: artist = Artist.objects.get(name="Bad Religion") names = [] for song in Song.objects.filter(artist=artist).only("name"): names.append(song.name) return hashlib.md5("".join(names).encode("utf-8")).hexdigest() Now, the SQL used is: SELECT "main_song"."id", "main_song"."name" FROM "main_song" WHERE "main_song"."artist_id" = 22729; But still, since I don't really need instances of model class Song I can use the .values() method which gives back a list of dictionaries. This is version 3: names = [] for song in Song.objects.filter(artist=a).values("name"): names.append(song["name"]) return hashlib.md5("".join(names).encode("utf-8")).hexdigest() This time Django figures it doesn't even … -
Adding custom filters to Django admin is easy!
I'm building a backend for a scraping tool that has two simple models Website and Page, where Website can have many pages. In a simplified form it looks like: class Website(models.Model): url = models.URLField(unique=True) class Page(models.Model): website = models.ForeignKey( 'Website', on_delete=models.CASCADE ... Read now -
Guide to Ansible/NGINX/uWSGI/Django, Part 2: Getting uWSGI Working with NGINX and Django
In Part 1 of this post, I described the trials, tribulations and ultimate success of running Ansible to provision a cloud server, which we do often here at Imaginary Landscape. Part 2 concludes the post by describing the process for getting uWSGI working with NGINX and Django. When I first tested the deployed website after doing the provisioning with Ansible, it failed with a not-very-descriptive "bad gateway" error. Luckily, uWSGI's own documentation provides an excellent tutorial on how to configure uWSGI, NGINX, and Django. Given the average quality of documentation one usually finds online, it's almost shocking how clear and thorough this tutorial is. It shows you step-by-step how to test each component until you get your Django app working with uWSGI and NGINX. It's great. The only downside is that because the tutorial is so thorough and because it assumes that you are setting up uWSGI, NGINX and Django from scratch (i.e., not with an Ansible script), working through it takes time. Nevertheless, when all three of those tools are in play, tracking down the cause of errors can be very difficult. Stripping the system down and checking each component in isolation, as the tutorial describes, might still be the best way forward. … -
Data Warehouse vs. Data Lake: Which Is Right for Your Enterprise App Development Effort?
So you’re building an app for your enterprise. While your primary purpose for building that app may take countless forms, that purpose is at least partly driven by the desire to collect and store “big data” that can be translated into business intelligence (BI). Why? BI allows you to translate your data into actionable information that helps you drive better business decisions. The post Data Warehouse vs. Data Lake: Which Is Right for Your Enterprise App Development Effort? appeared first on Distillery. -
Our Little Scoop
Last month we welcomed a little scoop to the family. Here is our daughter Uma. She has been eating ice cream since before she was born. She's our only child, and we love her so much. -
Our Little Scoop
Last month we welcomed a little scoop to the family. Here is our daughter Uma. She has been eating ice cream since before she was born. She's our only child, and we love her so much. -
How to Export Data to XLSX Files
A while ago I wrote an article about exporting data to different spreadsheet formats. As recently I was reimplementing export to Excel for the 1st things 1st project, I noticed that the API changed a little, so it's time to blog about that again. For Excel export I am using the XLSX file format which is a zipped XML-based format for spreadsheets with formatting support. XLSX files can be opened with Microsoft Excel, Apache OpenOffice, Apple Numbers, LibreOffice, Google Drive, and a handful of other applications. For building the XLSX file I am using openpyxl library. Installing openpyxl You can install openpyxl to your virtual environment the usual way with pip: (venv) pip install openpyxl==2.6.0 Simplest Export View To create a function exporting data from a QuerySet to XLSX file, you would need to create a view that returns a response with a special content type and file content as an attachment. Plug that view to URL rules and then link it from an export button in a template. Probably the simplest view that generates XLSX file out of Django QuerySet would be this: # movies/views.py from datetime import datetime from datetime import timedelta from openpyxl import Workbook from django.http … -
Our Little Scoop
Last month we welcomed a little scoop to the family. Here is our daughter Uma. She has been eating ice cream since before she was born. She's our only child, and we love her so much. -
How to Export Data to XLSX Files
A while ago I wrote an article about exporting data to different spreadsheet formats. As recently I was reimplementing export to Excel for the 1st things 1st project, I noticed that the API changed a little, so it's time to blog about that again. For Excel export I am using the XLSX file format which is a zipped XML-based format for spreadsheets with formatting support. XLSX files can be opened with Microsoft Excel, Apache OpenOffice, Apple Numbers, LibreOffice, Google Drive, and a handful of other applications. For building the XLSX file I am using openpyxl library. Installing openpyxl You can install openpyxl to your virtual environment the usual way with pip: (venv) pip install openpyxl==2.6.0 Simplest Export View To create a function exporting data from a QuerySet to XLSX file, you would need to create a view that returns a response with a special content type and file content as an attachment. Plug that view to URL rules and then link it from an export button in a template. Probably the simplest view that generates XLSX file out of Django QuerySet would be this: # movies/views.pyfrom datetime import datetimefrom datetime import timedeltafrom openpyxl import Workbookfrom django.http import HttpResponsefrom .models import … -
Guide to Ansible/NGINX/uWSGI/Django, Part 1: Running the Ansible Scripts
Here at Imaginary Landscape, we are frequently tasked with spinning up new cloud servers for our clients. Once a new server is online, we usually follow up by provisioning it with useful software. To automate that process, we began using Ansible a few years ago, and have had a lot of success with it. Provisioning is complicated by nature, however, and no provisioning attempt has been completely free of difficulty. This post examines a recent provisioning and uses it to expose issues that caused pain. Some of this is undoubtedly a case of the day-to-day getting in the way of tying up loose ends, but other aspects represent more generic problems. It is in the latter category where we hope this post might hold some wider value for the reader. Ansible offers a lot of flexibility in terms of how its configuration is laid out. A very pared-down version of ours looks like this: ansible-django-stack/ ├── extra-variables.yml ├── ansible/ └── ├── inventory.ini └── roles/ │ └── django/ │ └── tasks │ └── base.yml └── playbooks/ ├── playbook-all.yml └── playbook-all.retry Now let's look at what some of those files do. STEP 1: The Inventory File Our Ansible uses an inventory.ini file to obtain the … -
Meet Distillery’s Newest Scholarship Recipient: Andrew Chatman!
Well-functioning software is vital to keeping our world moving smoothly forward. At Distillery, we do our part by building reliable, secure, thoughtfully designed software that helps our clients build business success. We also do our part by supporting the next generation of developers: students who demonstrate outstanding promise in IT, computer science, or software engineering. The post Meet Distillery’s Newest Scholarship Recipient: Andrew Chatman! appeared first on Distillery.