分类: Python/Ruby
2013-09-11 17:00:06
1.建立一个工程
django-admin startproject serManager
cd serManager/
2.建立一个应用(虚拟机),下面的是一个通过ssh执行命令的应用
python manage.py startapp sshCMD
3.在settings文件添加应用,添加模板路径,设置数据库,设置静态文件路径
3.1添加应用
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'sshCMD'
)
3.2 添加模板路径
TEMPLATE_DIRS = (
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'/opt/serManager/sshCMD/Templates',
)
3.3 设置URL
from django.conf.urls import patterns, include, url
#add by hans 20130906
from sshCMD.views import index
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'serManager.views.home', name='home'),
# url(r'^serManager/', include('serManager.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
(r'^$',index),
)
3.4 测试
创建模板文件夹
root@ubuntu:/opt/serManager/sshCMD# mkdir Templates
创建模板文件
root@ubuntu:/opt/serManager/sshCMD# vim Templates/index.html
编辑视图
root@ubuntu:/opt/serManager/sshCMD# vim views.py
from django.shortcuts import render_to_response
def index(request):
return render_to_response('index.html',)
运行虚拟机
root@ubuntu:/opt/serManager/sshCMD# ../manage.py runserver 0.0.0.0:8080