An application that would let you create, edit and attempt quizzes (intended for tech quizzes), along with keeping a profile. .Here’s a breakdown of the project:

I used designs from the previous blog project(Bad at UI)

The project is divided into 2 applications:

  1. users: For handling user’s profile.
  2. quiz: For handling quizzes.
  1. Profile: A model for storing a user’s data (built-in User Model), bio, and profile pictures. I used Cloudinary for saving user’s uploads on the cloud.
  2. Quizzer: Stores quiz’s title, author (Foreign Key to User), private(For keeping quizzes unpublished), Reattempt( Boolean value for allowing multiple attempts), bg_pic (background picture for quiz modal, stored in the cloud with…


STATS FOR DS

The conditional probability of A given B (represented as P(A|B) ), is the probability of occurring event A given that event B has (or if ) occurred.

The Formula for calculating is P(A|B)=P(A∩B) / P(A). Let’s understand this formula with an example:

Let’s take the famous marbles in the bag example, we have 4 green and 3 red balls in the bag. What is the probability of drawing a green ball, when the first ball drawn is a red ball?

There are two events occurring in the question,

Event A: Drawing a red ball; Event B: Drawing a green ball.

Tree Diagram


STATS FOR DS

Let’s consider a trial of flipping a coin. The sample space is S={‘Head’,’ Tail’}.

If we flip the coin once, it will be either Head or Tail, the occurrence of one event(H or T) stops or affects the occurrence of the other event, hence they are called mutually exclusive events.

The probability of mutually exclusive events in a trial can be represented mathematically as: P(H AND T)=0 OR P(H ∩ T)=0;

Since there will be no common element (intersection) in the outcomes of the trial, either H or T (not overlapping sets).

Now consider a trial of flipping two coins…


PART-15

It’s now the time to add the reset password functionality. Without throwing all the URLs or imports or settings required, let me take you to step by step. We need a URL for a reset password, right?, So jump in the blog_project/urls.py and add the URL or link for the password reset, using the built-in PasswordResetView present in the auth view of django.contrib and specify the url and template name there.

...
path('password-reset/', auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'),
name='password_reset'),

As we specified the template name there, let’s go create that password_reset file (where the other files login, logout exists) in the users/templates/users folder

<h1>Trouble…


Part-14

Moving back to our blogapp, we had defined some views as follows

def home(request):
content={'posts':Post.objects.all()}
return render(request, 'blogapp/home.html',content)

def post(request):
return HttpResponse('<h1>A detailed post..</h1>')
def create(request):
return HttpResponse('<h1>Create a new post</h1>')
def update(request):
return HttpResponse('<h1>Update your post..</h1>')

def delete(request):
return HttpResponse('<h1>Delete a post..</h1>')

There are many more things to do here.., implement update, delete ,create new or view detailed post.Let’s use class based views here

Class based views have many built-in functionalities,let’s use them to allow users to create,read,update or delete a post using CreateView, DetailView or ListView, UpdateView and DeleteView

Import these views in the blogapp/views.py as follows,

from…


Part-13

When it comes to build forms, Django Forms can be really handy.It will automate a good amount of work as well as providing a really stable and secure functionality.

pic from 123RF for llustration

Django handles three distinct parts of the work involved in forms:

  1. Preparing and restructuring data to make it ready for rendering;
  2. Creating HTML forms for the data;
  3. Receiving and processing submitted forms and data from the client.

The parts 1 and 3 are usually fine for the most cases. But when it comes to the actual HTML forms rendering, sometimes it lacks some options.

In our DjangoReads project I used Bootstrap


Part-12

Update user profile

Let’s make the images auto resize when users upload them and add a new feature for the users to update their profile info.

So first create a UserUpdateForm in users/forms.py (as we want to show it on profile page)

class UserUpdateForm(forms.ModelForm):
class Meta:
model=User
fields=['username','email']

This lets our form know that we want to work with username and email fields,and i’ven’t added profile picand bio here, because the model for them is Profile so it’ll be in ProfileUpdateForm.So import the profile model and add this class

class ProfileUpdateForm(forms.ModelForm):
class Meta:
model=Profile
fields=['pic','bio']

UserUpdateForm will allow us to update our username…


Implement Luhn algorithm to generate valid credit card numbers with python

Credit Cards
Credit Cards

Credit card numbers follow certain patterns.

The very first number is the Major Industry Identifier (MII), which tells you what sort of institution issued the card.

  • 1 and 2 are issued by airlines
  • 3 is issued by travel and entertainment
  • 4 and 5 are issued by banking and financial institutions
  • 6 is issued by merchandising and banking
  • 7 is issued by petroleum companies
  • 8 is issued by telecommunications companies
  • 9 is issued by national assignment

The first six digits are the Issuer Identification Number (IIN). These can be used to look up where the card originated from.

  • Visa: 4*****
  • American…


part — 11

We have been adding profiles through admin page but we don’t want such on the production, instead we want the profile to be created automatically with the default image for every user(whenever a user is created). We can do this with signals in Django.

The signals are utilities that allow us to associate events() with actions(). We can develop a function that will run when a signal() calls it.

Let me give you a basic example:

models.py

from django.db import models
from django.db.models import signals
def create_cookie(sender, instance, created, **kwargs):
print "Let's start making cookies now"
class…


Part-10

let’s change the navigation items for the authenticated and anonymous users,for the anonymous users the navbar will show login and register urls,whereas for authenticated users it’ll show logout url.So to do this

In base.html,

<a href="{%url 'blog-home'%}" class="nav-item">DjangoReads</a>
<a href="{%url 'about'%}" class="nav-item">About</a>
{%if user.is_authenticated%}
<a href="{%url 'profile'%}" class="nav-item">Profile</a>
<a href="{%url 'logout'%}" class="nav-item">Logout</a>
{%else%}
<a href="{%url 'register'%}" class="nav-item">Register/Login</a>
{%endif%}

You can get information about the currently logged in user in templates with the {{ user }} template variable (this is added to the template context by default when you set up the project).{{ user.is_authenticated …

Atufa Shireen

Posting Django Tutorials with Beginner to Advanced Projects

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store