基础环境已经配置成功,环境搭建请参考《Nginx+uWSGI+Django+Python环境搭建》,我们使用Django来搭建第一个页面,hello,world!
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[root@hz Byrd]# python manage.py startapp blog #建立一个blog的项目 [root@hz Byrd]# vim Byrd/urls.py #增加 url(r'^$','blog.views.index'), [root@hz Byrd]# cat blog/views.py #方法1 from django.shortcuts import render from django.http import HttpResponse # Create your views here. def index(req): return HttpResponse('<h1>Hello,World</h1>') [root@hz Byrd]# mkdir blog/templates #方法2 [root@hz Byrd]# cat blog/templates/index.html <html> <head> <title>Hello,World</title> </head> <body> <h1>Hello,World</h1> </body> </html> [root@hz Byrd]# cat blog/views.py from django.shortcuts import render from django.http import HttpResponse from django.shortcuts import render_to_response # Create your views here. def index(req): return render_to_response('index.html',{}) |
到此,hello,world已经完成,更多请参考Django官方文档。SourceByrd's Weblog-https://note.t4x.org/code/django-hello-world/ SourceByrd's Weblog-https://note.t4x.org/code/django-hello-world/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!