Tôi đã thử làm theo một số hướng dẫn django để tạo thông tin đăng nhập nhưng tôi vẫn nhận được
Lỗi nhập tại /đăng nhập Không có mô-đun nào có tên đăng nhập
Cấu trúc tập tin của tôi là:
-src
-đăng nhập
-__init__.py
-admin.py
-models.py
-views.py
-dự án thử nghiệm
-__init__.py
-settings.py
-urls.py
settings.py
hệ điều hành nhập khẩu
BASE_DIR = '/Users/chrismeek/Documents/Python/Testenv'
BÍ MẬT_KEY = ''
GỠ LỖI = Đúng
TEMPLATE_DEBUG = Đúng
ALLOWED_HOSTS = []
CÀI ĐẶT_APPS = (
'Django.contrib.admin',
'django.contrib.auth',
'Django.contrib.contenttypes',
'django.contrib.sessions',
'Django.contrib.messages',
'Django.contrib.staticfiles',
'đăng nhập',
)
MIDDLWARE_CLASSES = (
'Django.contrib.sessions.middleware.SessionMiddleware',
'Django.middleware.common.CommonMiddleware',
'Django.middleware.csrf.CsrfViewMiddleware',
'Django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'Django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'testproject.urls'
WSGI_APPLICATION = 'testproject.wsgi.application'
CƠ SỞ DỮ LIỆU = {
'mặc định': {
'CÔNG CỤ': 'django.db.backends.sqlite3',
'TÊN': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = Đúng
USE_L10N = Đúng
USE_TZ = Đúng
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
'/Users/chrismeek/Documents/Python/Testenv/src/static/templates',
)
URL.py
từ mẫu nhập django.conf.urls, url, bao gồm
from django.contrib import admin
quản trị viên.autodiscover()
urlpatterns = mẫu ('',
url(r'^login', 'login.views.login', name='login'),
url(r'^auth/$', 'login.views.auth_view', name='auth_view'),
url(r'^logout/$', 'login.views.logout', name='logout'),
url(r'^loggedin/$', 'login.views.loggedin', name='loggedin'),
url(r'^invalid/$', 'login.views.invalid', name='invalid'),
url(r'^admin/', include(admin.site.urls)),
)
view.py
từ kết xuất nhập Django.shortcuts, render_to_response
từ django.http nhập HttpResponseRedirect
từ xác thực nhập django.contrib
từ django.corecontext_processors nhập csrf
# Tạo quan điểm của bạn ở đây.
đăng nhập chắc chắn (yêu cầu):
c = {}
c.update(csrf(request))
trả về render_to_response('login.html', c)
xác thực auth_view(yêu cầu):
tên người dùng = request.POST.get('tên người dùng', '')
mật khẩu = request.POST.get('mật khẩu', '')
người dùng = auth.authenticate(tên người dùng=tên người dùng, mật khẩu=mật khẩu)
nếu người dùng không phải là Không có:
auth.login(yêu cầu,người dùng)
trả về HttpResponseRedirect('đã đăng nhập')
khác:
trả về HttpResponseRedirect('không hợp lệ')
đăng nhập def (yêu cầu):
trả về render_to_response('loggedin.html', {'full_name': request.user.username})
def không hợp lệ_login(yêu cầu):
trả về render_to_response('invalid_login.html')
đăng xuất def (yêu cầu):
auth.logout(yêu cầu)
trả về render_to_response('logout.html')
Điều này đang khiến tôi phát điên và rất mong được giúp đỡ. Cảm ơn
Tôi là một lập trình viên xuất sắc, rất giỏi!