Django Note Taking App With Source Code

Django Note Taking App With Source Code

A Django Notes App users should be able to see or modify other users’ posts (in case this application gets deployed on a web server), this Django Note app can be easily converted between a blog and a note-taking app.

This Note App In Django also includes a downloadable Project With Source Code for free, just find the downloadable source code below and click to start downloading.

To start creating a Django Note Taking App, makes sure that you have PyCharm Professional IDE or any platform of django and its requirements Installed in your computer.

About ProjectProject DetailsDefinition
Project Name Django Note Taking App The Django Note Taking App is developed using Python DjangoHTML,CSS and JavaScript, This Django Notes A simple web application created with Django, a Python-based web framework, for taking notes.
Python version (Recommended)3.8 VersionPython 3.8 introduces some new syntax to the language, as well as a few small modifications to existing behavior and, most importantly, a slew of performance improvements, following in the footsteps of the previous 3.7 version.
Programming Language UsedPython Django LanguageDjango is a high-level Python web framework for building safe and maintainable websites quickly. Django is a web framework built by experienced developers that takes care of a lot of the heavy lifting so you can focus on developing your app instead of reinventing the wheel.
Developer Name itsourcecode.comFree projects containing source code in Java, PHP, Python, Django, VB.Net, Visual Basic, C, C++, C#, Javascript, and other languages are available on this website.
IDE Tool (Recommended)Sublime, Visual Studio, PyCharmSublime Text is a source code editor that is available for purchase. It comes with built-in support for a variety of programming and markup languages. Plugins, which are often community-built and maintained under free-software licenses, allow users to extend the functionality of the system. Sublime Text has a Python API to help with plugins.
Project Type Web ApplicationA web application, unlike computer-based software programs that operate locally on the device’s operating system, is application software that runs on a web server. The user uses a web browser with an active network connection to access web apps.
DatabaseSQLiteSQLite is a programming language that is used to create embedded software for devices such as televisions, cell phones, and cameras. It can handle HTTP requests with low to medium traffic. SQLite has the ability to compress files into smaller bundles with less metadata. SQLite is a temporary dataset that is used within an application to process data.
Django Note Taking App Overview

Reminders

To perform this python django project make sure that you have knowledge in the following:

  • CSS
  • HTML
  • Javascript
  • Database Management

Features Of This Django Note Taking App

  • Create Note
  • Read Note
  • Update Note
  • Delete Note
  • User Login/Logout
  • User Registration

In This Django Note Taking App Consist Of The Following Method:

  • django_project – In this method Which is the main method of the app.
  • blog – In this method which is the main feature of the app.
  • media – In this method which you can found all the media that being upload in this app.
  • users – In this method which is the users that manage the app.

Steps on how to create a Django Note Taking App With Source Code

Django Note Taking App With Source Code

  • Step 1: Open file.

    First , open “pycharm professional” after that click “file” and click “new project“.
    note app open file

  • Step 2: Choose Django.

    Second, after click “new project“, choose “Django” and click.
    note app create django

  • Step 3: Select file location.

    Third, select a file location wherever you want.
    note app file location

  • Step 4: Create application name.

    Fourth, name your application.
    note app application name

  • Step 5: Click create.

    Fifth, finish creating project by clicking “create” button.
    note app create project

  • Step 6: Start of coding.

    you are free to copy the following codes below in the given modules and method required.

The List Of Module Given Below Are Under The “Blog” Method

  • The Code Given Below Is For The “views.py” Module – you can add the following code below into your “views.py” under the “Blog” method.
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.auth.models import User
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
from .models import Post
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views import generic
from .forms import CreateViewForm, UpdateViewForm

# enabling case-insensitive search in MySQL databases
from django.db.models import Q, TextField
from django.db.models.functions import Lower
TextField.register_lookup(Lower, "lower")


# if users are allowed to view anyone's posts, not only theirs, then leave this and the next class uncommented
class PostListView(LoginRequiredMixin, ListView):
    model = Post
    template_name = 'blog/home.html'
    context_object_name = 'posts' # the name of a context variable with the queryset results
    ordering = ['-date_posted']
    paginate_by = 20

    # modifying the function for returning posts
    def get_queryset(self):
        # if there is a search query in the URL parameter, then use it to filter the results
        search_query = self.request.GET.get('search', '')
        # using Q for case-insensitive search in a MySQL database
        queryset = Post.objects.filter(Q(content__lower__contains=search_query)).order_by('-date_posted')
        return queryset


class PostDetailView(LoginRequiredMixin, DetailView):
    model = Post


# if users are allowed to view only their own posts, not anyone else's, then leave this and the next class uncommented
# class PostListView(LoginRequiredMixin, ListView):
#     model = Post
#     template_name = 'blog/home.html'
#     context_object_name = 'posts' # the name of a context variable with the queryset results
#     ordering = ['-date_posted']
#     paginate_by = 20
#
#     # modifying the function for returning posts
#     def get_queryset(self):
#         # if there is a search query in the URL parameter, then use it to filter the results
#         search_query = self.request.GET.get('search', '')
#         # using Q for case-insensitive search in a MySQL database
#         # filtering for posts where the user is the author
#         queryset = Post.objects.filter(Q(content__lower__contains=search_query)).filter(author_id=self.request.user.id).order_by('-date_posted')
#         return queryset
#
# class PostDetailView(LoginRequiredMixin, UserPassesTestMixin, DetailView):
#     model = Post
#
#     def test_func(self):
#         post = self.get_object()
#         if self.request.user == post.author:
#             return True
#         return False


class PostCreateView(LoginRequiredMixin, CreateView):
    model = Post
    form_class = CreateViewForm # making the class use an existing form with pre-defined validation rules
    template_name = 'blog/post_create.html'
    success_url = '/'

    def form_valid(self, form):
        form.instance.author = self.request.user
        return super().form_valid(form)


# if users are allowed to update or delete anyone's posts, not only theirs, then leave this and the next class uncommented
class PostUpdateView(LoginRequiredMixin, UpdateView):
    model = Post
    template_name = 'blog/post_update.html'
    form_class = UpdateViewForm

    def form_valid(self, form):
        form.instance.author = self.request.user
        return super().form_valid(form)


class PostDeleteView(LoginRequiredMixin, DeleteView):
    model = Post
    success_url = '/'
    template_name = 'blog/post_delete.html'


# if users are allowed to update or delete only their own posts, then leave this and the next class uncommented
# class PostUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):
#     model = Post
#     template_name = 'blog/post_update.html'
#     form_class = UpdateViewForm
#
#     def form_valid(self, form):
#         form.instance.author = self.request.user
#         return super().form_valid(form)
#
#     def test_func(self):
#         post = self.get_object()
#         if self.request.user == post.author:
#             return True
#         return False
#
#
# class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
#     model = Post
#     success_url = '/'
#     template_name = 'blog/post_delete.html'
#
#     def test_func(self):
#         post = self.get_object()
#         if self.request.user == post.author:
#             return True
#         return False


# defining actions when the CSRF error occurs
# the reason parameter here is optional and will only be displayed in logs
def csrf_failure(request, reason=""):
    current_page = request.path
    # iterating through all the pages that contain forms where the user can potentially encounter the CSRF error
    # and calling respective functions again
    try:
        if '/post/new' in current_page:
            return PostCreateView.as_view()(request)
        elif '/update' in current_page:
            return PostUpdateView.as_view()(request)
        elif '/delete' in current_page:
            return PostDeleteView.as_view()(request)
        # redirect to the homepage in any other case, e.g. after login
        else:
            return HttpResponseRedirect('/')
    # if there was any error in calling the respective function, then redirect to the homepage
    except:
        return HttpResponseRedirect('/')

In this module which is the index module of the Blog method.

  • The Code Given Below Is For The “urls.py” Module – you can add the following code below into your “urls.py” under the “Blog” method.
from django.urls import path
from .views import PostListView, PostDetailView, PostCreateView, PostUpdateView, PostDeleteView
from . import views

urlpatterns = [
    path('', PostListView.as_view(), name='blog-home'),
    path('post/<int:pk>/', PostDetailView.as_view(), name='post-detail'),
    path('post/new/', PostCreateView.as_view(), name='post-create'),
    path('post/<int:pk>/update/', PostUpdateView.as_view(), name='post-update'),
    path('post/<int:pk>/delete/', PostDeleteView.as_view(), name='post-delete'),
]

In this module which is the URL configuration module under Blog method.

  • The Code Given Below Is For The “models.py” Module – you can add the following code below into your “models.py” under the “Blog” method.
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
from PIL import Image


# defining a database table for posts
class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    date_posted = models.DateTimeField(default=timezone.now) # recording the timestamp when a new entry is created
    author = models.ForeignKey(User, on_delete=models.CASCADE) # ForeignKey defines a "many-to-one relationship"
    image = models.ImageField(default='',upload_to='images',blank=True,null=True)
    audio = models.FileField(default='',upload_to='audio',blank=True,null=True)

    def __str__(self):
        return self.title

    # defining a URL for a new entry
    def get_absolute_url(self):
        return reverse('post-detail', kwargs={'pk': self.pk})

# model names should be singular, for example, Post, because they represent a single object
# fields should be written in lowercase and with underscores
# The __str__ method defines a human-readable representation of the model in the Django admin site
# CASCADE defines that when a user is deleted, all his/her entries are deleted as well

In this module which you can found classes to be call under Blog method.

The List Of Module Given Below Are Under The “Users” Method

  • The Code Given Below Is For The “views.py” Module – you can add the following code below into your “views.py” under the “Users” method.
from django.shortcuts import render
from .forms import UserRegisterForm
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.views import LoginView
from django.http import HttpResponseRedirect


def register(request):
    # if it is a POST request (a registration form is being submitted)
    if request.method == 'POST':
        form = UserRegisterForm(request.POST)
        # if it passes validation:
        if form.is_valid():
            form.save()
            # automatically authenticate the new user after registration
            new_user = authenticate(username=form.cleaned_data['username'],
                                    password=form.cleaned_data['password1'],
                                    )
            login(request, new_user)
            # redirect to the homepage with a success message
            return HttpResponseRedirect('/?account=success')
    # if it is a GET request (a registration form is just being loaded)
    else:
        form = UserRegisterForm()
    # if it is a GET request or the form doesn't pass validation, then return the registration form page
    return render(request, 'users/register.html', {'form': form})


# adding more context to the default 'LoginView' class-based view
class LoginLogout(LoginView):

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context.update({
            'message': 'You have logged out!',
            'tag': 'success'
        })
        return context


# adding a custom logout function
def logout_view(request):
    # logging the user out
    logout(request)
    # calling the 'LoginLogout' that has updated context for the 'LoginView'
    return LoginLogout.as_view(template_name='users/login.html')(request)

In this module which is the index module of the Users method.

I have here the list of Best Python Project with Source code free to download for free, I hope this can help you a lot.

Downloadable Source Code Below.

Anyway, if you want to level up your programming knowledge, especially python, try this new article I’ve made for you Best Python Projects with source code for Beginners. But If you’re going to focus on web development using Django, you can download here from our list of Best Django Projects with source code based on real-world projects.

How To Run The Django Note Taking App?

Step 1: Extract/unzip the file

Step 2: Go inside the project folder, open cmd and type the following commands to install Django Framework and run the webserver:

1.) pip install -r requirements.txt

2.) python manage.py runserver

Step 3: Finally, open the browser and go to localhost:8000

Summary

The system is built fully in Django Framework in back-end and HTML, CSS in front-end. It has full-featured user interface with all the functionalities

This Article is the way to enhance and develop our skills and logic ideas which is important in practicing the python programming language which is most well known and most usable programming language in many company.

Related article below

Inquiries

If you have any questions or suggestions about Django Note Taking App, please feel free to leave a comment below.

2 thoughts on “Django Note Taking App With Source Code”

Leave a Comment