Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django Tips & Tricks #10 - Log SQL Queries To Console
Django ORM makes easy to interact with database. To understand what is happening behing the scenes or to see SQL performance, we can log all the SQL queries that be being executed. In this article, we will see various ways to achieve this. Using debug-toolbar Django debug toolbar provides panels to show debug information about requests. It has SQL panel which shows all executed SQL queries and time taken for them. When building REST APIs or micro services where django templating engine is not used, this method won't work. In these situations, we have to log SQL queries to console. Using django-extensions Django-extensions provides lot of utilities for productive development. For runserver_plus and shell_plus commands, it accepts and optional --print-sql argument, which prints all the SQL queries that are being executed. ./manage.py runserver_plus --print-sql ./manage.py shell_plus --print-sql Whenever an SQL query gets executed, it prints the query and time taken for it in console. In [42]: User.objects.filter(is_staff=True) Out[42]: SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."is_staff" = true LIMIT 21 Execution time: 0.002107s [Database: default] <QuerySet [<User: anand>, <User: chillar>]> Using django-querycount Django-querycount provides a middleware to show SQL query count and … -
Django Tips & Tricks #10 - Log SQL Queries To Console
Django ORM makes easy to interact with database. To understand what is happening behing the scenes or to see SQL performance, we can log all the SQL queries that be being executed. In this article, we will see various ways to achieve this. Using debug-toolbar Django debug toolbar provides panels to show debug information about requests. It has SQL panel which shows all executed SQL queries and time taken for them. When building REST APIs or micro services where django templating engine is not used, this method won't work. In these situations, we have to log SQL queries to console. Using django-extensions Django-extensions provides lot of utilities for productive development. For runserver_plus and shell_plus commands, it accepts and optional --print-sql argument, which prints all the SQL queries that are being executed. ./manage.py runserver_plus --print-sql ./manage.py shell_plus --print-sql Whenever an SQL query gets executed, it prints the query and time taken for it in console. In [42]: User.objects.filter(is_staff=True) Out[42]: SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."is_staff" = true LIMIT 21 Execution time: 0.002107s [Database: default] <QuerySet [<User: anand>, <User: chillar>]> Using django-querycount Django-querycount provides a middleware to show SQL query count and … -
Vue Tutorial with Django RESTful API — Vue CLI 3 Tutorial In Depth
Throughout this Vue tutorial with Django RESTful API, we are going to learn to use the Vue CLI v3 (In beta — 3.0.0-beta.15 as of this writing) to generate our Vue front-end application. In this tutorial, we're going to see: How to install the latest version of Vue CLI — version 3 How to use various features of the Vue CLI v3 How to use the Vue CLI v3 to create a front-end How to set environment variables for development and production How to add a proxy to forward API calls How to install and add Vue CLI plugins manually etc. The Vue CLI v3 provides a new experience to developers as it allows you to easily generate new Vue projects with zero initial configuration but once your project needs more control you have the possibility to add more configuration options using plugins. Unlike create-react-app, you can customize your configuration without ejecting but only via Vue CLI plugins. The Vue CLI v3 is a complete tooling system that provides many features, out of the box, such as: Interactive project scaffolding via @vue/cli. Zero configuration rapid prototyping via @vue/cli and @vue/cli-service-global. A runtime dependency (@vue/cli-service) that provides many features: It's upgradeable, … -
Full-Stack Vue Tutorial with Django RESTful API — CRUD Using Axios with Vue
Throughout this tutorial with Vue.js and Axios we'll see how to add CRUD (Create, Read, Update and Delete) methods with a Vue front-end and a Python Django RESTful API back-end. Axios is a promise-based modern http client library that runs on the browser and the server through Node.js. Axios works asynchronously and allows you to make HTTP calls to REST endpoints and consume REST APIs. Using Axios with Vue We'll use Axios to send API or HTTP calls (We'll write code for sending GET, POST, DELETE and PUT HTTP requests.) from a Vue.js interface to a RESTful API back-end built with Django. First things first, let's get the back-end code. Getting the Django Back-End In this tutorial, we'll be focusing on building the Vue.js and Axios front-end so we'll be using a previously built Django API available from this GitHub repository Using the following command, you can clone the back-end code: $ git clone https://github.com/techiediaries/django-crm $ cd django-crm Next, you need to create a virtual environment and install packages using pipenv: $ pipenv install Next, activate the virtual environment using: $ pipenv shell Finally, create and migrate the database and run the local development server using: $ python manage.py migrate … -
python django Automated Testing
Automated TestingThe automated testing are simple routines that checks the operation of your code . There are some tests which tests the small part of the code and others are which tests the overall operation of the program automated tests are tests which are done by the system for us like we create a set of tests and then we make changes to our app and test if the code works as if we it were originally intended to work without performing time consuming manual testingBenefits of TestingTest will save Time:If we change any of the components of the code could cause unexpected application behavior checking that it still works means running the test through your code functionality with twenty different variations of your test data just to make sure its working properly this is not a good use of time we can do this test in seconds with automated testing like writing the automated test is more beneficial than testing your application manually Test prevent the problem: they can prevent the coming problems from identifying them early before you could fall in any problemsTest make the code more attractive: if you have made an amazing software then also most developers … -
Handling repetitive tests in Django
When writing tests (unit and/or functional), one of the goal is to cover all edge-cases. DDT is a great way to write such tests; here is how to do so in Python and Django. -
Handling repetitive tests in Django
When writing tests (unit and/or functional), one of the goal is to cover all edge-cases. DDT is a great way to write such tests; here is how to do so in Python and Django. -
Angular 6 Tutorial with Django RESTful API — Adding Angular Material Design 6 UI By Example
In the previous tutorial, you have seen how you can install the Angular CLI 6 and generate a brand new Angular 6 front-end application. In this tutorial, we'll be learning how to use Angular 6 Material Design to build a beautiful and professional grade UI interface. What's Material Design and Angular Material 6 Material Design is a design language created by Google in 2014 that dictates a set of principles and guidelines for creating UIs including motion (animations) and interaction (gestures). Angular Material 6 is the implementation of Material Design for Angular 6. It offers a plethora of components and patterns for navigation, forms, buttons and layouts. In this tutorial, we'll see how to add Material Design to Angular 6 in two ways: The long way: by following a bunch of steps manually. This works for Angular 4, 5 and Angular 6. The short way: by using ng add command to quickly add Angular Material in one step using Angular 6 Schematics. This method only works with Angular 6+. Step1: Installing Angular Material and Angular CDK Head over to your terminal, navigate inside your created Angular front-end application and then run the following commands to install Angular Material 6 and … -
Install Jupyter Notebooks in a Virtual Environment
Let's install Jupyter for a di... -
Angular 6 Tutorial with Django RESTful API — Building Bootstrap 4 UIs
In this Angular 6 tutorial we'll learn how to use Bootstrap 4 with Angular 6 to build professional UIs. Angular 6 is the latest version of Angular when writing this tutorial and Bootstrap 4 is the latest version of Bootstrap — The most popular CSS framework. You can use Bootstrap to create professional looking interfaces without being a CSS designer. In this tutorial, we'll particularly look at how to add Bootstrap 4 to Angular projects generated using Angular CLI 6. In the previous tutorial, we've built a web application with Angular 6 and Django. In this part, we're going to style the UI interface with Bootstrap 4, after installing and setting up the framework in the Angular 6 front-end. In the previous tutorial we’ve: - Installed Angular CLI v6. - Generated a new front-end application using Angular CLI v6. - Created some UI components. In this tutorial, we'll be using the following versions of libraries: Angular 6 and Angular CLI 6. Bootstrap 4. Different Ways to Integrate Bootstrap 4 with Angular 6 There are many ways to add Bootstrap 4 to Angular 6 projects: Installing bootstrap and jquery via npm and add adding scripts and styles to angular.json. Importing bootstrap … -
Django Models Best Practices
A list of tips for designing better models in Python/Django. -
Django CORS
An introduction to CORS and how to enable it in Django. -
How to configure Sass and Bower with django-compressor - part 1 (local config)
Quick guide on how to configure Django with Sass, Bower and django-compressor -
How to configure Sass and Bower with django-compressor - part 2 (deployment to Heroku and S3)
Quick guide on how to deploy Django with Sass, Bower and django-compressor to Heroku and S3 -
A Basic SEO for Django
A Basic SEO for Django. -
Classy Django REST Framework Release
Release of Classy Django REST Framework -
10 Django apps you're not using but should be
Description of 10 essential apps every Django developer should be using in their projects -
Uploading files from the frontend to Amazon S3
How to upload files from the frontend straight to S3 without sending to the server using django -
3 Django apps for sending great e-mails
3 Django apps for debugging and sending HTML styled e-mails -
Controlling access: a Django permission apps comparison
There are many ways to handle permissions in a project. This post highlights the main differences and approaches taken by some popular Django third party apps to handle permissions. -
Database concurrency in Django the right way
When developing applications which have real-time requirements or other specific needs for running asynchronous tasks outside the web application, it is common to adopt a task queue such as Celery. This allows, for example, for the server to handle a request, start an asynchronous task responsible of doing some heavyweight processing, and return an answer while the task is still running. Here, we are considering a similar scenario: a request is made, and the server has to do some processing on the request. Ideally, we want to separate the high time-demanding parts from the view processing flow, so we run those parts in a separate task. Now, let's suppose we have to do some database operations both in the view and the task when the request happens. If not done carefully, those operations can be a source for issues that can be hard to track. -
Metaprogramming and Django - Using Decorators
While programming is about, in some way, doing code to transform data, metaprogramming can be seen as the task of doing code to change code. This category is often used to help programmers to enhance the readability and maintainability of the code, help with separation of concerns and respect one of the most important principles of software develop -
Django and React Boilerplate as an Asset in Software Development
Here at Vinta we believe that programmers, not processes, nor code, are the most important assets on software engineering. Due to that, we believe in using every tool available in order to facilitate our programmers' lives. One of our favorites is our boilerplate. If you are unfamiliar with the concept, a boilerplate is "any code block that is reus -
How I test my DRF serializers
How I test my DRF serializers In this blog post, I will show the whats and whys on testing Django REST Framework serializers. First, some context. Here is the model setup we are going to use for this example: from django.db import models class Bike(models.Model): COLOR_OPTIONS = ((&#39;yellow&#39;, &#39;Yellow&#39;), (&#39;red&#39;, &#39;Red&# -
Don't forget the stamps: testing email content in Django
When developing a web app how often do you check the emails you send are all working properly? Not as often as your web pages, right? That's ok, don't feel guilty, emails are hard to test and they are often someone's else responsibility to write and take care. This doesn't mean we should give up on them. There are some things we can do to prevent e