django+python+eclipse 入门hello,打印时间

一、下载Django模块


下载地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/


二、新建Django工程



django+python+eclipse 入门hello,打印时间_第1张图片


django+python+eclipse 入门hello,打印时间_第2张图片


django+python+eclipse 入门hello,打印时间_第3张图片


三、测试Django工程新创建的工程是否运行能正常运行


创建三个脚本文件

  • manage.py 管理Django项目的脚本,提供一些管理项目的工具例如django数据库同步,和创建模块等功能
  • settings.py 项目的默认设置,包括数据库信息,调试标志以及一些重要的全局变量
  • urls.py URL模式映射到你应用程序的配置文件上

django+python+eclipse 入门hello,打印时间_第4张图片


四、添加与创建视图的脚本文件views.py


django+python+eclipse 入门hello,打印时间_第5张图片


五、编辑代码


编辑views.py文件,输入代码如下

from django.http import HttpResponse
import datetime

def current_datetime(request):
    now = datetime.datetime.now()
    html = "<html><body>It is now %s.</body></html>" % now
    return HttpResponse(html)

编辑urls.py文件

代码如下

from django.conf.urls import patterns, include, url
from djtest.views import current_datetime

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

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


六、运行工程


django+python+eclipse 入门hello,打印时间_第6张图片

你可能感兴趣的:(django+python+eclipse 入门hello,打印时间)