raymondaksu / Project-023-Blog-Website-Django-02

A blog website comprises Bootstrap, Django and SQLite.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Project-023-Blog-Website-Django-02

A blog website comprises Bootstrap, Django and SQLite.

Intructions of Django Blog

  1. Create environment and activate it
  2. Install django
  3. Create requirement.txt, .gitignore and .env files
  4. Install decouple
  5. Move SECRET_KEY to .env and edit settigs.py
  • from decouple import config SECRET_KEY = config('SECRET_KEY')
  1. Change folder name to src and Start project
  2. Create an app and edit settings>INSTALLED_APPS
  3. Migrate
  4. Create superuser
  5. Run server and check from browser
  6. Create model (Category and Post)
  7. Register the modelsin admin.py
  8. Install pillow and edit requirement.txt
  9. Make migrations + migrate
  10. Run server and check, add items to models manually from admin panel
  11. Add str function to models to make them seen other than an object
  12. Add MEDIA_URl and MEDIA_ROOT to seetings.py and edit urls.py. Create media_root folder
  13. Edit models.py for uploading images (paths)
  14. For generating slug create signals.py file, and add a function to apps.py
  15. Edit signals.py
  16. Create Comment, Like and View classes in models. Make migrations + migrate
  17. Create forms.py. Add PostForm and CommentForm
  18. Edit views -> post_list
  19. Edit settings.py ->TEMPLATES
  • 'DIRS': [BASE_DIR, "templates"]
  1. Create folder templates under src folder and create file base.html
  2. Create folders templates/blog under blog folder and create post_list.html
  3. Create post_list function in views, edit both urls.py files
  4. Create post_create function in views.(❗️ adding files, getting author info )
  5. Create post_create.html and edit urls.py
  6. uuid -> create file utils.py. Inside create a 10 char-long unique id to improve slugify
  7. Create post_details function in views, edit urls.py, create post_details.html file
  8. Pace post titles in post_list page anchor to link user to post_detail page
  9. Add update and delete posts as above
  10. Apply bootstrap starter template to base.html
  11. Create navbar.html under src/templates
  12. Include navbar in base.html
  13. Create folders static/blog under application (blog) and create main.css file. (This is sth django wants)
  14. Add main.css file's link to head section of base.html and add {% load static %} on top
  15. Edit settings.py as
  • STATICFILES_DIRS = [BASE_DIR / "static"]
  1. Apply a card style to post_list page with bootstrap.
  2. Get a kit script from fontawesome and apply to base.html to icons for comment, like and view
  3. Add functions to Post class in models.py to retrieve count of comments, likes and views
  4. Import CommentForm to views and add comment to post_detail function
  5. Add a method to Post class to retrieve all the comments of a post
  6. Display all the comments of a post using a for loop in post_detail page, and add a form to the same page to get comments from the user
  7. Import Like to views + add a like function + add like func to urls + create a form in post_detail.html (❗️ Note the action url)
  8. Add an if statement to post_detail.html do display delete and update buttons. If the user is the author, he should see update & delete buttons for his own post
  9. Now the problem is that a user can reach delete & update pages to any post by typing the url path to address bar. A temporary solution below. After using authentication we will change the way we do it.
  10. Install HttpResponse from django.http in views and add an if statement to post_update and post_delete as
  • if request.user.id != obj.author.id
  • return HttpResponse("You are not authorized")
  1. Install django-crispy-forms with pip and add crispy_forms to INSTALLED_APPS in settings.py. This third party app is for styling forms w bootstrap.
  2. Edit the detail, create, update and delete pages as follows:
  • add {% load crispy_forms_tags %}
  • and change previously form.as_p to form|crispy
  1. Style these pages with bootstrap
  2. Create users app + add the new app to INSTALLED_APPS in settings.py
  3. Create a Profile class in users > models add fields. Add a function to point the path to save the uploaded profile pictures of the user
  4. pip freeze > requiremets.txt
  5. makemigrations & migrate
  6. Register Profile in users > admin.py
  7. In order to automatically create a userf profile just after adding a user create a signals.py file (see the code)
  8. Add a ready method in users > apps.py to make signals.py take effect

About

A blog website comprises Bootstrap, Django and SQLite.


Languages

Language:Python 63.7%Language:HTML 34.3%Language:CSS 2.0%