Django配置表单

来源:互联网 发布:知轩藏书论坛 编辑:程序博客网 时间:2024/05/23 21:06

配置流程


将html与css分离:
将html文件放入templates文件中
css放入建立的static/css文件中
方便管理


DATABASES:

DATABASES = {    'default': {        'ENGINE': 'django.db.backends.mysql',        'NAME': "testdjango", #数据库的名字        'USER': "root",       #连到数据库的用户        'PASSWORD': "960724", # 密码        'HOST': "127.0.0.1"   # 数据库的ip地址    }}

TEMPLATES:
TEMPLATES 中 将根目录与html做一个连接:

'DIRS': [os.path.join(BASE_DIR, 'templates')]

为static设置路径:

STATICFILES_DIRS = [    os.path.join(BASE_DIR, 'static')]

migration生成数据表:
makemigrations appname : Crate new migrations for apps
mmigrate appname: Updates database schema


views.py 中创建相应的处理:

def getform(request)    return render(request, ‘messageform.html’)

注意避免与内置的html文件重名


urls.py 中创建映射

url(r’^form/$’, getform)
原创粉丝点击