Python-django安装

  1. download django:

    https://www.djangoproject.com/download/ 

    现在需要的版本,如Django-1.3.7.tar.gz

  2. 解压Django-1.3.7.tar.gz:

    tar zxvf Django-1.3.7.tar.gz

    cd Django-1.3.7

  3. 使用root用户调用python命令 安装django到ubuntu:

    sudo python setup.py install

    if there is no error info,good luck!

  4. 测试django 模块是否能正常运行:

    >>> import django
    >>>
    if there is no error info ,good luck!

  5. 测试django自带测试服务器:

    1. python manage.py runserver

    2. 正确结果现实如下:

      Validating models...

      0 errors found
      Django version 1.3.7, using settings 'csvt01.settings'
      Development server is running at http://127.0.0.1:8000/
      Quit the server with CONTROL-C.
      [11/Oct/2015 22:21:17] "GET / HTTP/1.1" 200 2051

  6. 目前为止,django-1.3.7 安装基本完成

  7. 开始创建django工程:

    1. django-admin.py startproject mysite 创建mysite 工程;

    2. mysite/
      __init__.py
      manage.py
      settings.py
      urls.py

  8. 设置工程的时区和语言:

    1. vim settings.py

    2. LANGUAGE_CODE = 'zh-cn'

    3. TIME_ZONE = 'Asia/Shanghai'

  9. 把即将要实现的应用的名称写到INSTALLED_APPS 元组中:

    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'blog',
        # Uncomment the next line to enable the admin:
        # 'django.contrib.admin',
        # Uncomment the next line to enable admin documentation:
        # 'django.contrib.admindocs',
    )

  10. 修改urls.py(就是    url config文件),指定应用访问路径

    1. vim urls.py like this:

      from django.conf.urls.defaults import patterns, include, url

      # Uncomment the next two lines to enable the admin:
      # from django.contrib import admin
      # admin.autodiscover()

      urlpatterns = patterns('',
          # Examples:
          # url(r'^$', 'csvt01.views.home', name='home'),
          # url(r'^csvt01/', include('csvt01.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)),
          url(r'^blog/index', include(blog.views.index)),
      )

  11. 创建一个应用:

    1. 使用django创建一个blog application:

      django-admin.py startapp blog

      /blog:

      __init__.py

      models.py

      tests.py

      views.py


https://docs.python.org/2/tutorial/modules.html

你可能感兴趣的:(django,ubuntu,vim)