Trevel-Book blog project one of my django project. Here, i create a full blog project to use all of blog functionality, using language python framework Django.
In this project i used virtual environment, two apps, media folder, static folder, templates and others pip library/packages.
virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them. This is one of the most important tools that most of the Python developers use.
- pip install virtualenv [For install virtual environment for python]
- virtualenv --version [for check your virtual environmentversion]
- py -m venv your_virtualenv_name [for create and start your virtual environment]
- cd Scrripts\activate [for activate your virtual environment]
- deactivate [for deactivate your virtual environment]
Django-crispy-forms supports several frontend frameworks, such as Twitter Bootstrap (versions 2, 3, and 4), Uni-form and Foundation. You can also easily adapt your custom company's one, creating your own, see the docs for more information. You can easily switch among them using CRISPY_TEMPLATE_PACK setting variable.
Install latest stable version into your python environment using pip:
- pip install django-crispy-forms
If you want to install development version (unstable), you can do so doing:
- pip install git+git://github.com/django-crispy-forms/django-crispy-forms.git@dev#egg=django-crispy-forms
Once installed add crispy_forms to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = (
...
'crispy_forms',
)
For add template packs within django-crispy-forms:
#bootstrap, bootstrap3, bootstrap4, uni-from
CRISPY_TEMPLATE_PACK = 'bootstrap4'
In Django, files which are uploaded by the user are called Media or Media Files. Here are some examples:
- A user uploaded image, pdfs, doc files etc while publishing a post.
- Images of products in an e-commerce site.
- User's profile image. etc...
Just as with static files, to serve media files we have do add some configurations in our settings.py file.
Media files depend upon two configurations,
- MEDIA_ROOT,
- MEDIA_URL
In settings.py file:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
In main project urls.py file:
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
In static folder we store our all of css, js, bootstrap file to use those file in our project.
settings added
from django.conf import settings
static and static_url added
from django.conf.urls.static import static
for load static folder in templates
{% load static %}
In this project i used two web-app this are App_Login & App_Blog .
-
App-Login:
- In app login i create one custom model which is connected to Django provided User model in One-To-One connection.
- And also i create three custom forms for Signup , Profile-update and for profile photo.
- I also used django provided UserCreationForm for Signup and UserChangeForm form profile update.
-
App-Blog:
- In app-blog i used three custom models. those are...
- Blog model, for blog posts.
- Comment model, for comment in blogs.
- Likes model, for like blogs.
- In this three custom models i used one of foreign-key from User model.
- Relation with User model:
- User model and Blog model. [One-To-Many]
- User model and Comment model. [One-To-Many]
- User model and Likes model. [One-To-Many]
- In Comment and Likes custom models i used one of foreign-key from Blog model.
- Blog model and Comment model. [One-To-Many]
- Blog model and Likes model. [One-To-Many]
- And i also used one of custom form which name CommentForm. For customize Comment model.
- In app-blog i used three custom models. those are...
This all about this project, carry on developement. Be happy and stay safe. 😎