如果你想传给form字段,可以先做一个model的object实例,把request.user传给这个object实例的相关字段,然后把这个实例传给forms实例即可。
首先我们要新建一个用户名,用来登陆管理网站,可以使用如下命令:\x0d\x0apython manage.py createsuperuser\x0d\x0a输入想要使用的用户名:\x0d\x0a\x0d\x0aUsername (leave blank to use 'administrator'): user01\x0d\x0a输入email:\x0d\x0a\x0d\x0aEmail address: (在这里输入你的自己的邮箱帐号)\x0d\x0a输入密码,需要输入两次,并且输入密码时不会显示出来:\x0d\x0a\x0d\x0aPassword:\x0d\x0aPassword (again):\x0d\x0a当两次密码都相同的时候,就会提示超级帐号创建成功。\x0d\x0aSuperuser created successfully.\x0d\x0a\x0d\x0a运行服务:\x0d\x0a\x0d\x0apython manage.py runserversettings.pyMIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.staticfiles',
)
urls.py
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)