How to include css files:
-------------------------------------
django-admin startproject maheshnewsproject
py manage.py startapp testapp
-->Add application in settings.py
-->Create a folder templates
-->Update this one in settings.py
TEMPLATE_DIR = BASE_DIR/'templates'
-->Create a static folder
Inside static folder create css and images folders.
STATIC_DIR = BASE_DIR/'static'
STATICFILES_DIRS = [STATIC_DIR]
views.py
-------------
def news_info(request):
return render(request,'testapp/index.html')
index.html
-----------------
<title></title>
<link rel="stylesheet" href="{% static 'css/demo.css' %}">
<body>
<h1>Welcome To MAHESH NEWS Portal</h1>
<img src="{% static 'images/news.jpg' %}" alt="">
<ul>
<li><a href="#">Movies Information</a></li>
<li><a href="#">Sports Information</a></li>
<li><a href="#">Politics Information</a></li>
</ul>
</body>
views.py
-------------
def movies_info(request):
head_msg = 'Movies Information'
sub_msg1 = 'OG will come very soon......'
sub_msg2 = 'Planning for Aashiqui-3 with Mahesh Sir & Sunny Leone'
sub_msg3 = 'Dont go for mpovies....practice django....'
type = 'movies'
my_dict = {'head_msg':head_msg,'sub_msg1':sub_msg1,'sub_msg2':sub_msg2,
'sub_msg3':sub_msg3,'type':type}
return render(request,'testapp/news.html',my_dict)
def sports_info(request):
head_msg = 'Sports Information'
sub_msg1 = 'IPL will conducted in March'
sub_msg2 = 'T20 ENG and IND'
sub_msg3 = 'India won the 3rd t20 with 15 runs yesterday'
type = 'sports'
my_dict = {'head_msg':head_msg,'sub_msg1':sub_msg1,'sub_msg2':sub_msg2,
'sub_msg3':sub_msg3,'type':type}
return render(request,'testapp/news.html',my_dict)
def politics_info(request):
head_msg = 'Politics Information'
sub_msg1 = 'AP DyCM Pawan Kalyan'
sub_msg2 = 'India PM was Modi'
sub_msg3 = 'Upcoming AP CM...........?'
type = 'politics'
my_dict = {'head_msg':head_msg,'sub_msg1':sub_msg1,'sub_msg2':sub_msg2,
'sub_msg3':sub_msg3,'type':type}
return render(request,'testapp/news.html',my_dict)
news.html
----------------
<body>
<h1>{{head_msg}}</h1>
<ul>
<li>{{sub_msg1}}</li>
<li>{{sub_msg2}}</li>
<li>{{sub_msg3}}</li>
</ul>
{% if type == 'movies' %}
<img src="{% static 'images/1.jpg' %}" alt="">
<img src="{% static 'images/2.jpg' %}" alt="">
<img src="{% static 'images/3.jpg' %}" alt="">
{% elif type == 'sports' %}
<img src="{% static 'images/4.jpg' %}" alt="">
<img src="{% static 'images/5.jpg' %}" alt="">
<img src="{% static 'images/6.jpg' %}" alt="">
{% elif type == 'politics' %}
<img src="{% static 'images/7.jpg' %}" alt="">
<img src="{% static 'images/8.jpg' %}" alt="">
<img src="{% static 'images/9.jpg' %}" alt="">
{% endif %}
</body>
urls.py
----------
path('', views.news_info),
path('movies/', views.movies_info),
path('sports/', views.sports_info),
path('politics/', views.politics_info),
demo.css
--------------
body{
background: yellow;
color: red;
text-align: center;
}
ul{
font-size: 20px;
text-align: left;
}
img{
height: 250px;
width: 300px;
margin: 25px;
border: 5px solid red;
}
CHAPTR-4:Working with Models & Databases
=======================================