Eclipse下开发Django
来源:互联网 发布:小程序淘宝客怎么样 编辑:程序博客网 时间:2024/06/16 16:02
1.新建Django项目
选择sqlite数据库
2.创建博客模块app
3.测试新建的模块是否正常
4.编辑代码
4.1修改 blog.models.py
- from django.db import models
- from django.contrib import admin
- # Create your models here.
- class BlogPost(models.Model):
- title = models.CharField(max_length=150)
- body = models.TextField()
- timestamp = models.DateTimeField()
- class BlogPostAdmin(admin.ModelAdmin):
- list_display = ('title','body','timestamp')
- admin.site.register(BlogPost,BlogPostAdmin)
4.2修改 blog.views.py
- # Create your views here.
- from django.template import loader,Context
- from django.http import HttpResponse
- from blog.models import BlogPost
- def archive(request):
- posts = BlogPost.objects.all()
- t = loader.get_template('archive.html')
- c = Context({'posts':posts})
- return HttpResponse(t.render(c))
4.3 修改mysite.setting.py
- 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',
- )
4.4 修改urls.py
- from django.conf.urls import patterns, include, url
- # Uncomment the next two lines to enable the admin:
- from django.contrib import admin
- admin.autodiscover()
- from blog.views import *
- urlpatterns = patterns('',
- # Examples:
- # url(r'^$', 'mysite.views.home', name='home'),
- # url(r'^mysite/', include('mysite.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/$', archive),
- )
5.建立样式网页模板
注意:请在模块blog下添加templates文件夹
5.1 编辑archive.html
- {% extends "base.html" %}
- {% block content %}
- {% for post in posts %}
- <h1>{{ post.title}}</h1>
- <p>{{ post.timestamp|date:"1, F jS"}}</p>
- <p>{{ post.body }}</p>
- {% endfor %}
- {% endblock %}
5.2 编辑base.html
- <html>
- <style type="text/css">
- body { color: #edf; background: #453; padding: 0 5em; margin:0 }
- h1 { padding: 2em lem; background:#675 }
- h2 { color: #bf8; border-top: 1px dotted #fff; margin-top: 2em }
- p { margin: lem 0 }
- </style>
- <body>
- <h1>mysite.example.com</h1>
- {% block content %}
- {% endblock %}
- </body>
- </html>
6.同步数据库
设置你的账号和密码,为登陆blog的管理后台作准备。
7.运行成功
登陆界面,登陆账号是初始化数据库的时候设定的,密码也是那时候设定的。
0 0
- Eclipse下开发Django
- eclipse下搭建django开发环境
- 配置Eclipse 下的Django开发环境(Eclipse + Pydev)
- Eclipse+PyDev开发Django在Ubuntu下的配置
- windows下 eclipse+python+django开发环境搭建
- windows下eclipse中的Django开发环…
- 用Python+Django在Eclipse环境下开发web网站
- 用Python+Django在Eclipse环境下开发web网站
- 用Python+Django在Eclipse环境下开发web网站
- 用Python+Django在Eclipse环境下开发web网站
- 用Python+Django在Eclipse环境下开发web网站
- 【django】用Python+Django在Eclipse环境下开发web网站
- mac下开发 django
- Eclipse + Pydev下配置Django
- Eclipse环境下配置django
- eclipse +dev+django开发网站
- [django]ubuntu下django 开发 环境配置
- linux下使用pydev eclipse Mysql-python 搭建django开发环境
- Spring MVC数据绑定大全
- 南阳 485 A*B Problem
- 2.1 设置action栏
- 南阳 105 9的余数
- Chromium on Android: 认识Chromium WebView
- Eclipse下开发Django
- 数据挖掘概述
- 11 insert buffer
- ACM学习计划
- hdu 1249 三角形
- sscanf和sprintf()函数使用说明
- 畅想网络的开放模式
- dubbo分布式SOA框架
- Delphi中str函数用法