-
-
Save eayoungs/723a1929141ea299d5fd 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>{{page_name}}</title> | |
</head> | |
<body> | |
<h1>{{page_name}}</h1> | |
{% block content %} | |
{% endblock content %} | |
</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
{% extends "base.html" %} | |
{% block content %} | |
<p>Welcome to my home page.</p> | |
{% endblock content %} |
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.conf.urls.defaults import patterns, include, url | |
from django.views.generic.simple import direct_to_template | |
urlpatterns = patterns('', | |
url(r'^$', | |
direct_to_template, | |
{'template': 'home.html', | |
'extra_context': {'page_name': 'Home'}}, | |
name='home'), | |
url(r'^other$', | |
direct_to_template, | |
{'template': 'other.html', | |
'extra_context': {'page_name': 'Other Page'}}, | |
name='other'), | |
) |
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
{% extends "base.html" %} | |
{% block content %} | |
<p>This is some other page in my site that also extends the base template.</p> | |
{% endblock content %} |
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.conf.urls.defaults import patterns, include, url | |
from views import ExtraContextTemplateView | |
urlpatterns = patterns('', | |
url(r'^$', | |
ExtraContextTemplateView.as_view(template_name='home.html', | |
extra_context={'page_name': 'Home'}), | |
name='home'), | |
url(r'^other$', | |
ExtraContextTemplateView.as_view(template_name='other.html', | |
extra_context={'page_name': 'Other Page'}), | |
name='other'), | |
) |
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 | |
class ExtraContextTemplateView(TemplateView): | |
extra_context = None | |
def get_context_data(self, *args, **kwargs): | |
context = super(ExtraContextTemplateView, self).get_context_data(*args, **kwargs) | |
if self.extra_context: | |
context.update(self.extra_context) | |
return context |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment