Last active
September 4, 2020 05:01
-
-
Save poojansmobio/6fb142ff6733fc27f171d4e4513924ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>{{ site_title }}</title> | |
</head> | |
<body> | |
<h2> {{ indextitle }} </h2> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
from .views import * | |
from . import views | |
urlpatterns = [ | |
path('',IndexView.as_view(),name="index"), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.views.generic import TemplateView | |
from .models import * | |
""" | |
Base View | |
""" | |
class Base(TemplateView): | |
""" | |
This is Base class | |
The functions and variables used | |
in this class can be used whichever | |
class inherits this Base class. | |
""" | |
def get_global_settings(self): | |
""" | |
Function to get values from database | |
""" | |
self.global_setting = tbl_setting_master.objects.all().values('key','value') | |
def get_context_data(self, **kwargs): | |
context = super(Base,self).get_context_data(**kwargs) #creating context variable | |
setting = self.get_global_settings() #calling function | |
main_title = next(item for item in setting if item["key"] == "main_title") #value to variables. | |
context['site_title'] = main_title #Passing variable to context | |
return context | |
""" | |
Index View | |
""" | |
class IndexView(Base): | |
""" | |
This class is inherited from Base class so the | |
context variable of Base class will be defined directly added. | |
""" | |
template_name = "index.html" | |
""" | |
We use more functions for more operations | |
""" | |
def indexmethod(self): | |
self.variable_of_this_func = "IndexTitle" | |
return self.variable_of_this_func | |
def get_context_data(self, **kwargs): | |
""" | |
This variables are of IndexView which is for index only. | |
""" | |
context = super(IndexView,self).get_context_data(**kwargs) | |
index_title = self.indexmethod() | |
context['indextitle'] = index_title | |
return context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment