• Django简单界面开发


    编译环境采用的是PyCharm

    新建Django项目

    如图:其中views.py是自己创建的

    会创建一个test2   venv  manage.py文件

    venv是一个依赖性文件

    创建一个new python file

    views.py:

    from django.http import HttpResponse
    import time

    def current_time(request):
    return HttpResponse("Current time is:"+time.strftime('%Y-%m-%d %H:%M:%S'))
    首先从django.http模块引入HttpResponse类
    然后定义了一个叫current_time 的视图,每个视图函数至少有一个参数,通常被叫做request
    这个函数只有简单的一行代码: 它仅仅返回一个HttpResponse对象。

    进行url配置
    在urls.py中配置:
    urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^current_time/$', current_time),

    ]

    运行结果:
    http://127.0.0.1:8000/current_time/

    
    
    
  • 相关阅读:
    macOS免费的NTFS读写软件
    Python模块和模块引用(一)
    Python Class (一)
    Ubuntu系统管理systemd
    Case Closed?
    The 'with' and 'as' Keywords
    Buffering Data
    rstrip
    堆排序
    堆 续9
  • 原文地址:https://www.cnblogs.com/1998lu/p/9123045.html
Copyright © 2020-2023  润新知