Chapter 4. Building a Social Website

In the previous chapter, you learned how to create sitemaps and feeds, and you built a search engine for your blog application. In this chapter, you will develop a social application. You will create functionality for users to login, logout, edit, and reset their password. You will learn how to create a custom profile for your users, and you will add social authentication to your site.

This chapter will cover the following points:

  • Using the authentication framework
  • Creating user registration views
  • Extending the User model with a custom profile model
  • Adding social authentication with python-social-auth

Let's start by creating our new project.

Creating a social website project

We are going to create a social application that will allow users to share images they find on the Internet. We will need to build the following elements for this project:

  • An authentication system for users to register, log in, edit their profile, and change or reset their password
  • A followers' system to allow users to follow each other
  • Functionality to display shared images and implement a bookmarklet for users to share images from any website
  • An activity stream for each user that allows users to see the content uploaded by the people they follow

This chapter addresses the first point.

Starting your social website project

Open the terminal and use the following commands to create a virtual environment for your project and activate it:

mkdir env
virtualenv env/bookmarks
source env/bookmarks/bin/activate

The shell prompt will display your active virtual environment as follows:

(bookmarks)laptop:~ zenx$

Install Django in your virtual environment with the following command:

pip install Django==1.8.5

Run the following command to create a new project:

django-admin startproject bookmarks

After creating the initial project structure, use the following commands to get into your project directory and create a new application named account:

cd bookmarks/
django-admin startapp account

Remember to activate the new application in your project by adding it to the INSTALLED_APPS setting in the settings.py file. Place it in the INSTALLED_APPS list before any of the other installed apps:

INSTALLED_APPS = (
    'account',
    # ...
)

Run the next command to sync the database with the models of the default applications included in the INSTALLED_APPS setting:

python manage.py migrate

We are going to build an authentication system into our project using the authentication framework.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset