17👍
For static HTML you could use Flatpages app.
You could also serve rendered templates (which could contain only static HTML) but you will need a view:
from django.shortcuts import render_to_response
def some_view(request):
return render_to_response('sometemplate.html')
About redirection, basically you can’t redirect to HTML page by just giving the filename, even if it were statically served by the web server you would still be using a URL that points to that file.
26👍
direct_to_template no longer works in Django 1.8. Here is how to do it in 1.8, in the urls.py:
from django.views.generic import TemplateView
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name="your_static.html"), name='whatever'),
]
- Django's get_current_language always returns "en"
- How do I simulate connection errors and request timeouts in python unit tests
20👍
You can render a template without a view using the generic view direct_to_template
.
Redirecting to success.html isn’t the way to go in django since success.html doesn’t have an associated URL. You always have to bind the template to an url via a view (direct_to_template is a view which gets all its arguments from the conf in urls.py, but it’s still a view)
11👍
I’m pretty sure this isn’t what OP wanted to do, but if someone wants to render something without a view, (for sending an email or appending to other html code), you can use this:
from django.template.loader import render_to_string
html = render_to_string('template.html', params)
7👍
Use lambda function.
urlpatterns = [
path('', lambda request: render(request, 'homepage.html'))
]
- How does this Man-In-The-Middle attack work?
- Create a canonical "parent" product in Django Oscar programmatically