Mac下django简单安装配置步骤
2019/10/10/17:45:27 阅读:1814 来源:谷歌SEO算法 标签:
黑猫SEO
下面一起来看看在Mac下django简单安装配置步骤,希望这篇文章对各位带来帮助.
一、安装软件包并创建项目
- $sudopipinstalldjango
- $sudopython-c"importdjango;printdjango.VERSION"
- (1,7,0,'final',0)
- $sudodjango-adminstartprojectcmdb#创建项目
- $sudodjango-adminstartappcmdb#创建应用
二、修改配置
1、修改settings.py,添加cmdb应用,以及其他设置:
- INSTALLED_APPS=(
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'cmdb',
- )
- DATABASES={
- 'default':{
- 'ENGINE':'django.db.backends.mysql',
- 'NAME':'cmdb',
- 'USER':'cmdb',
- 'PASSWORD':'cmdb',
- 'HOST':'localhost',
- 'PORT':'3306',
- }
- }
- LANGUAGE_CODE='zh-cn'
- TIME_ZONE='Asia/Shanghai'
2、修改urls.py和views.py,urls.py内容如下:
- fromdjango.conf.urlsimportpatterns,include,url
- fromdjango.contribimportadmin
- urlpatterns=patterns('',
- #Examples:
- #url(r'^$','cmdb.views.home',name='home'),
- #url(r'^blog/',include('blog.urls')),
- url(r'^admin/',include(admin.site.urls)),
- url(r'^index/','cmdb.views.index'), --phpfensi.com
- )
views.py内容如下:
- fromdjango.shortcutsimportrender
- fromdjango.httpimportHttpResponse
- defindex(req):
- returnHttpResponse('<h1>hellowelcometodjango!</h1>')
3、测试,启动django
#sudo python manage.py runserver
访问:http://localhost:8000/index
热门评论