Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
在安装python之前先安装sqlite-devel,否则随后运行django时可能会报错,错误内容为django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3。运行命令
1
yum install sqlite-devel
当前版本是2.6.6,安装的版本是2.7.11
下载python的二进制包 Python-2.7.11.tgz 并解压
进入解压后的目录中 运行 如下命令
1 2 3
./configure make make install (权限有问题,则执行 sudo make install)
sudo su - root cd /usr/bin rm -rf python ln -s ${PYTHON_HOME}/python python
此时python安装成功,但可能会导致centos的yum命令无法使用,提示如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$ yum There was a problem importing one of the Python modules required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or verify that the module is installed correctly.
It's possible that the above module doesn't match the current version of Python, which is: 2.7.11 (default, Apr 19 2016, 14:52:39) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq
from rest_framework.decorators import api_view from rest_framework.response import Response from rest_framework import status from django.http import HttpResponse import os import sys
# REST接口测试 @api_view(['GET', 'POST']) defrestapitest(request): response = HttpResponse() if request.method == 'POST': response.write("This method is post.") return response elif request.method == 'GET': response.write("This method is get.") return response
创建rest/urls.py
1 2 3 4 5 6 7 8 9 10 11 12 13
# -*- coding: utf-8
from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patterns