from django.http import HttpResponse
def index(request):
return HttpResponse('Hello, Django!')
配置urls.py文件
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^myproj/', include('myproj.foo.urls')),
(r'^$', 'myproj.helloworld.index'),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# (r'^admin/', include(admin.site.urls)),
)
from django.contrib import admin
from more_with_admin.examples import models
class DocumentAdmin(admin.ModelAdmin):
pass
class CommentAdmin(admin.ModelAdmin):
pass
admin.site.register(models.Document, DocumentAdmin)
admin.site.register(models.Comment, CommentAdmin)
(2) 在seettings中的INSTALLED_APPS 添加
'django.contrib.admin'
(3) 在urls中添加
from django.contrib import admin admin.autodiscover() 与
(r'^admin/(.*)', admin.site.root),
运行python manage.py sqlall admin
(4) 运行 python manage.py runserver,将会出现以下信息
Validating models...
0 errors found.
Django version 0.96-pre, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
现在你可以访问http://127.0.0.1:8000/admin/,登录 9、Django 数据库设置
创建db.py
#coding=utf-8
#import os
#os.environ['DJANGO_SETTINGS_MODULE'] = 'myproj.settings'
from django.conf import settings
settings.configure(
DATABASE_ENGINE='mysql',
DATABASE_NAME='django_demo',
DATABASE_USER='root',
DATABASE_PASSWORD='',
DATABASE_HOST='localhost',
DATABASE_PORT='',
)