Chapter 2. Discuss – a Hacker News Clone
In this chapter, we'll be creating a web app similar to Hacker News or Reddit, where users can share and discuss links to web content. We'll call the application Discuss. To keep things simple, we'll be emulating the minimalistic look of Hacker News, which is text only and has a very simple interface. Reddit, on the other hand, is much more visually rich and has a lot of extra features that we won't be adding to our site.
Here's an outline of what we'll be covering in this chapter:
- Allowing users to submit their own content
- Allowing users to vote on content submitted by other users
- Ranking the user-submitted content based on simple algorithms
- Preventing spammers from abusing our site using captchas
Chapter code packs
If you have developed a few Django applications, you'll probably know that for most applications, a lot of the code and configurations that you do when starting out is the same. You set up the database in the same way, maybe changing the Database (DB) name and user/pass pairs, you set up your media, static URL, and root paths, and then you add user authentication using the built-in auth contrib
application and the provided views, only creating minimal templates that are good enough to get the job done in the start.
Walking you through the basic setup at the start of every chapter would be very boring—both for you to read and for me to write. Instead, I've provided what I call Code Packs. These are zip
files that contain the Django application already set up so that we can jump straight to the interesting parts of the code instead of having to go through the tedious setup process again and again.
Don't worry, I won't skip any new Django features that we haven't looked at yet. Each code pack contains code that has already been explained to you in previous chapters. For instance, the code pack for this chapter contains a Django application that has the user registration, login, and logout views, templates, and URLs already set up. This is the stuff that we have already looked at in detail in the previous chapter.
To use these code packs, you will need to download them, unzip them in the project root folder, and create a virtual environment for them. Then, you'll need to run the following command to have Django installed in your new virtual environment:
> pip install django > python manage.py migrate
Once you've done all these steps, you'll be ready to start working on the fun parts of the application. For all the following chapters, I've given you the link to the code pack and I assume that you have already extracted and set up a virtual environment for it.