Django by Example

Django by Example

Language: English

Pages: 474

ISBN: 1784391913

Format: PDF / Kindle (mobi) / ePub


Create your own line of successful web applications with Django

About This Book

  • Learn Django by building four fully-functional, real-world web applications from scratch
  • Develop powerful web applications quickly using the best coding practices
  • Integrate other technologies into your application with clear, step-by-step explanations and comprehensive example code

Who This Book Is For

If you are a web developer who is completely new to or familiar with Django and wants to make the most of it, this book is for you. Some basic knowledge of Python, HTML, and JavaScript is recommended.

What You Will Learn

  • Build practical real-world web applications with Django
  • Use Django with other technologies such as Redis, Celery, Solr and Memcached
  • Develop pluggable Django applications
  • Create advanced features, optimize your code and use the cache framework
  • Add internationalization to your Django projects
  • Enhance the user experience using JavaScript and AJAX
  • Add social features to your projects
  • Build RESTful APIs for your applications

In Detail

Django is a powerful Python web framework designed to develop web applications quickly, from simple prototypes to large-scale projects. Django encourages clean, pragmatic design, and provides developers with a comprehensive set of tools to build scalable web applications.

This book will walk you through the creation of four professional Django projects, teaching you how to solve common problems and implement best practices.

The book begins by showing you how to build a blog application, before moving on to developing a social image bookmarking website, an online shop and an e-learning platform. You will learn how to build a search engine and implement a user activity stream. Furthermore, you will create a recommendation engine, an e-commerce coupon system and a content management system. The book will also teach you how to enhance your applications with AJAX, create RESTful APIs and setup a production environment for your Django projects.

After reading this book, you will have a good understanding of how Django works and how to integrate it with other technologies to build practical, advanced, web applications.

Style and approach

This is an easy-to-follow guide to building four different production-ready Django projects. Each project focuses on a particular area of the framework and each topic within the projects is explained with practical examples and includes best practice recommendations.

CSS3: The Missing Manual (3rd Edition)

Django Design Patterns and Best Practices

Magento PHP Developer's Guide

Building E-Commerce Solutions with WooCommerce (2nd Edition)

WordPress Web Application Development

 

 

 

 

 

 

 

 

 

 

 

 

 

accordingly to include the paginator using the right variable, like this: {% include "pagination.html" with page=page_obj %} Open http://127.0.0.1:8000/blog/ in your browser and check that everything works the same way as with the previous post_list view. This is a simple example of a class-based view that uses a generic class provided by Django. You will learn more about class-based views in Chapter 10, Building an e-Learning Platform and successive chapters. Summary In this chapter, you

send an e-mail like this: >>> from django.core.mail import send_mail >>> send_mail('Django mail', 'This e-mail was sent with Django.', 'your_account@gmail.com', ['your_account@gmail.com'], fail_silently=False) send_mail() takes the subject, message, sender, and list of recipients as required arguments. By setting the optional argument fail_silently=False, we are telling it to raise an exception if the e-mail couldn't be sent correctly. If the output you see is 1, then your e-mail was

run the following command to create the database migration for the new model: python manage.py makemigrations You will get this output: Migrations for 'account': 0001_initial.py: - Create model Profile Next, sync the database with the following command: python manage.py migrate You will see an output that includes the following line: Applying account.0001_initial... OK Edit the admin.py file of the account application and register the Profile model in the administration site, like this:

Users, you will see the user you created before. The Post model of your blog application has a relationship with this User model. Remember, it is a relationship defined by the author field. Adding your models to the administration site Let's add your blog models to the administration site. Edit the admin.py file of your blog application and make it look like this: from django.contrib import admin from .models import Post admin.site.register(Post) Now, reload the admin site in your browser.

id=id, slug=slug, available=True) cart_product_form = CartAddProductForm() r = Recommender() recommended_products = r.suggest_products_for([product], 4) return render(request, 'shop/product/detail.html', {'product': product, 'cart_product_form': cart_product_form, 'recommended_products': recommended_products}) Now edit the shop/product/detail.html template of the shop application and add the following code after {{ product.description|linebreaks }}: {% if recommended_products %}

Download sample

Download