2
我試圖沿着一些Django的教程遵循創建一個登錄,但我一直在得到導入錯誤在/登錄沒有名爲登錄
導入錯誤模塊/登錄無模塊命名登錄
我的文件結構是:
-src
-logins
-__init__.py
-admin.py
-models.py
-views.py
-testproject
-__init__.py
-settings.py
-urls.py
settings.py
import os
BASE_DIR = '/Users/chrismeek/Documents/Python/Testenv'
SECRET_KEY = ''
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'logins',
)
MIDDLEWARE_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'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
'/Users/chrismeek/Documents/Python/Testenv/src/static/templates',
)
urls.py
from django.conf.urls import patterns, url, include
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
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)),
)
views.py
from django.shortcuts import render, render_to_response
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.corecontext_processors import csrf
# Create your views here.
def login(request):
c = {}
c.update(csrf(request))
return render_to_response('login.html', c)
def auth_view(request):
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request,user)
return HttpResponseRedirect('loggedin')
else:
return HttpResponseRedirect('invalid')
def loggin(request):
return render_to_response('loggedin.html', {'full_name': request.user.username})
def invalid_login(request):
return render_to_response('invalid_login.html')
def logout(request):
auth.logout(request)
return render_to_response('logout.html')
這是推動我堅果和希望得到任何幫助。由於
請[編輯]與錯誤和追溯的**全文**你的問題。 – MattDMo 2014-08-28 20:20:56