django1.7 配置demo教程(环境搭建)
来源:互联网 发布:免费最新看电影的软件 编辑:程序博客网 时间:2024/04/30 07:56
最近又用到django做个简单项目,1年多没用过了有些手生,按理说没啥问题吧
下面是一个简单的环境搭建demo过程:
前提条件:准备了python2.7已经安装
1、搭建django环境
下载 https://bootstrap.pypa.io/ez_setup.py
保存本地
执行 python ez_setup.py
2、安装pip
C:\Python27\Scripts>easy_install.exe pip
3、安装diango
pip install Django==1.7
3、创建Django project
C:\Python27\Lib\site-packages\django\bin\django-admin.py startproject bluescf
4、在工程目录下执行python manage.py runserver
打开浏览器:http://127.0.0.1:8000/
5、创建一个app+模型
python manage.py startapp demosite
注意:默认已经创建了一个 bluescf的app
6、添加模板的路径
settings.py 添加下面代码
import os.path
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'),
)
7、在templates添加 html文件,暂停:index.html
8、创建views.py
from django.http import HttpResponsefrom django.shortcuts import render_to_responsefrom django.template import RequestContext, loader #return HttpResponse("Hello, world. You're at the poll index.") def index(request):# View code here... t = loader.get_template('index.html') c = RequestContext(request, {'foo': 'bar'}) return HttpResponse(t.render(c), content_type="application/xhtml+xml")
9、配置 urls.py
#coding=utf-8 from django.conf.urls import patterns, include, urlfrom django.contrib import adminimport viewsurlpatterns = patterns('', # Examples: # url(r'^$', 'bluescf.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^$', views.index, name='home'),#默认直接进入views的index方法)
10、打开浏览器:http://127.0.0.1:8000/ 预览效果,一切正常说明就ok了。
其实我的views.py里的index方法 一开始不是这样子写得,原来写法:
def index(request):return render_to_response('index.html')
结果报错了,
千万不用去百度和google搜索 __init__() got an unexpected keyword argument 'mimetype' ,没用的,会出来一堆没用的信息,搜出我这篇文章算是你的福气,^_^。
这种问题明显就是api升级了用的老的写法(django1.3之前我都这样写)
所以需要我们好好查api:http://django.readthedocs.org/en/latest/topics/http/shortcuts.html#django.shortcuts.render_to_response
看到这就没有问题了吗?
其实还是有问题的,
def index(request):# View code here... t = loader.get_template('index.html') c = RequestContext(request, {'foo': 'bar'}) return HttpResponse(t.render(c), content_type="text/xml")
奥,那就太不幸了,会提示你:
This page contains the following errors:
Below is a rendering of the page up to the first error.
别到处乱抄网上的例子,知道一些细节很重要的。
有什么问题,大家可以跟我交流(CSDN技术群QQ群:221057495)。
- django1.7 配置demo教程(环境搭建)
- (二)搭建环境之django1.8
- Django1.3环境搭建
- Django1.11环境搭建
- Django 环境搭建(CentOS65 + Django1.7 + mySQL5.1)
- python34+Django1.7+mysql5.5环境搭建(win7)
- 搭建django环境(python3.6+django1.10.3)
- python3.4 + django1.8的环境搭建
- Django1.3.1 with python2.5 环境配置
- Mac 10.10下Python2.7+Django1.7+MySQL5.5环境搭建
- 认识django1.6(1)---官方环境搭建及poll应用练习过程总结
- android搭建环境demo
- SpringMvc环境搭建Demo
- Webrtc Demo环境搭建
- SSH商城Demo --- 五、搭建SSH开发环境,配置基本信息
- Ubuntu12.04系统下写你的第一个Django1.5应用(一)--环境搭建--数据库,时区,语言,配置
- PHP环境搭建:Windows 7下安装配置PHP+Apache+Mysql环境教程
- PHP环境搭建:Windows 7下安装配置PHP+Apache+Mysql环境教程
- 热天了而万科人了我就空间和微软看见过
- Web图形样式基础2
- 第一章绪论总结
- 【google apec 2015 1c】 挖矿、打地铁 最短路djstra、+*计算器
- Qt程序 发布过程
- django1.7 配置demo教程(环境搭建)
- 推荐系统review
- Java Socket编程
- [2014 Regional]牡丹江 H Hierarchical Notation 做题实录
- 每天一个linux命令(10):cat 命令
- 第七周项目三—某员工的工资问题
- 全面理解Javascript闭包和闭包的几种写法及用途
- phpstorm的一些基础设置和快捷键
- 第7周项目--串联电阻