Hello World:APP容器节点(Django)配置

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/RivenDong/article/details/101631012

1. 前言

环境:Ubuntu 16.04 Server
学习Docker容器与容器云APP容器节点配置汇总:

2. view.py文件

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
import redis

def hello(request):
	str=redis.__file__
	str+="<br>"
	r=redis.Redis(host='db',port=6379,db=0)
	info=r.info()
	str+=("Set Hi <br>")
	r.set('Hi','HelloWorld-APP1')
	str+=("Get Hi: %s <br>" % r.get('Hi'))
	str+=("Redis Info: <br>")
	str+=("Key: Info Value")
	for key in info:
		str+=("%s:%s <br>"%(key, info[key]))
	return HttpResponse(str)

3. setting.py文件

ALLOWED_HOSTS = ['192.168.5.128']

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'helloworld',
]

4. urls.py文件

"""redisweb URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.10/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include,url
from django.contrib import admin
from helloworld.views import hello

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^helloworld$',hello)
]

猜你喜欢

转载自blog.csdn.net/RivenDong/article/details/101631012