首页 > 代码库 > Django的安装
Django的安装
安装Django:
wget https://www.djangoproject.com/m/releases/1.7/Django-1.7.2.tar.gz tar -zxf Django-1.7.2.tar.gz cd Django-1.7.2/ python setup.py install **** error: Traceback (most recent call last): File "setup.py", line 4, in <module> from setuptools import setup, find_packages ImportError: No module named setuptools ****
缺少setuptools模块,需要安装该模块:
下载最新setuptools:https://pypi.python.org/packages/source/s/setuptools/
tar -zxf setuptools-9.1.tar.gz cd setuptools-9.1/ python setup.py install cd ../Django-1.7.2/ python setup.py install
测试安装是否成功:
python Python 2.7.3 (default, Mar 18 2014, 05:13:23) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django #无报错则成功。
# django-admin startproject dj01 #创建一个工程dj01 # tree dj01/ #默认工程目录树 dj01/ ├── dj01 │ ├── __init__.py │ ├── settings.py #框架配置文件 │ ├── urls.py #url配置文件 │ └── wsgi.py └── manage.py 1 directory, 5 files # django-admin startapp blog # tree blog blog ├── admin.py ├── __init__.py ├── migrations │ └── __init__.py ├── models.py #模块配置文件 ├── tests.py └── views.py #视图配置文件
----修改配置文件:
settings.py INSTALLED_APPS = ( ‘blog‘, #添加该行 )
# vim urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns(‘‘,
url(r‘^blog/index$‘, ‘blog.views.index‘), #当用户访问blog/index的时候,指定访问到blog目录下的views模块的index方法
url(r‘^blog/abc$‘, ‘blog.views.abc‘), #同上
)
# vim views.py #blog目录下的views.py文件,定义具体的访问内容,视图页面 from django.shortcuts import render from django.http import HttpResponse # Create your views here. def index(req): return HttpResponse(‘<hl>Hello welcome to Django!</hl>‘) def abc(req): return HttpResponse(‘dddddddddddd‘)
---ok,下面测试
# python manage.py runserver #启动服务,测试! Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run ‘python manage.py migrate‘ to apply them. January 08, 2015 - 15:23:20 Django version 1.7.2, using settings ‘dj01.settings‘ Starting development server at http://127.0.0.1:8000/ #如果不指定,默认启动127.0.0.1 8000 Quit the server with CONTROL-C.
为了方便测试:
# python manage.py runserver 0.0.0.0:8000 #指定启动ip和端口,0.0.0.0表示所有ip
Django的安装
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。