python Django Minimal App
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Django Minimal App相关的知识,希望对你有一定的参考价值。
from django.conf.urls import url
from django.http import HttpResponse
DEBUG = True
SECRET_KEY = '4l0ngs3cr3tstr1ngw3lln0ts0l0ngw41tn0w1tsl0ng3n0ugh'
ROOT_URLCONF = __name__
TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates'},]
def home(request):
color = request.GET.get('color', '')
return HttpResponse('<h1 style="color:' + color + '">Welcome to the Tinyapp\'s Homepage!</h1>')
from django.template import engines
from django.template.loader import render_to_string
def about(request):
title = 'Tinyapp'
author = 'Vitor Freitas'
about_template = '''<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<h1>About {{ title }}</h1>
<p>This Website was developed by {{ author }}.</p>
<p>Now using the Django's Template Engine.</p>
<p><a href="{% url 'homepage' %}">Return to the homepage</a>.</p>
</body>
</html>
'''
django_engine = engines['django']
template = django_engine.from_string(about_template)
html = template.render({'title': title, 'author': author})
return HttpResponse(html)
urlpatterns = [
url(r'^$', home, name='homepage'),
url(r'^about/$', about, name='aboutpage'),
]
from django.conf.urls import url
from django.http import HttpResponse
DEBUG = True
SECRET_KEY = '4l0ngs3cr3tstr1ngw3lln0ts0l0ngw41tn0w1tsl0ng3n0ugh'
ROOT_URLCONF = __name__
def home(request):
return HttpResponse('<h1 style="color:red">Welcome to the Tinyapp\'s Homepage!</h1>')
urlpatterns = [
url(r'^$', home),
]
以上是关于python Django Minimal App的主要内容,如果未能解决你的问题,请参考以下文章
python 在不涉及整个项目的情况下调用django collectstatic,灵感来自https://github.com/syntarsus/minimal-django
Django学习——python manage.py startapp app-name新建app报错问题
python27+django创建app
python web框架 Django的APP以及目录介绍 django 1.11版本
Django创建工程以及app和基本使用_python
Django创建工程以及app和基本使用_python