从django.contrib.auth.forms导入UserCreationForm导致django.core.exceptions.AppRegistryNotReady:应用尚未加载

时间:2019-12-10 13:47:59

标签: python html django

因此,我看到许多有关臭名昭著的“ django.core.exceptions.AppRegistryNotReady:应用尚未加载”的问题。但是我找不到任何人可以解决我的问题,因为它与我的INSTALLED_APPS没有任何关系,只有在我注释掉UserCreationForm时它才会消失。我正在尝试创建一个基本的注册页面,而UserCreationForm是实现此目的的最佳方法。那么有人知道我需要做什么来解决这个问题吗?我对这种情况和Django的了解不足,也似乎无济于事,但这似乎是一个简单的解决方法。谢谢您的帮助:)。

以下是我认为所有相关的代码。

在settings.py

    INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'hello.views',]

urls.py

from django.contrib import admin
from django.urls import path
from hello.views import myView
from hello.views import myHome
from hello.views import home
from hello.views import index
from hello.views import game
from hello.views import main
from hello.views import signup
from django.contrib.auth import views as auth_views
from django.views.generic.base import TemplateView
from django.conf.urls import url, include
urlpatterns = [
    url(r'^admin/',admin.site.urls),
    url(r'^hello/',include('hello.urls')),
    path('sayHello/', myView),
    path('home/',home,name='Home'),
    path('game/',game,name="Game"),
    path('home/game.html',game),
    path('home/home.html',home),
    path('game/game.html',game),
    path('game/home.html',home),
    path('main/',main),
    path('signup/',signup, name="signup"),
    url(r'^login/$', auth_views.LoginView.as_view(template_name= 'login.html'), name='login'),
    url(r'^logout/$', auth_views.LogoutView.as_view(template_name= 'logged_out.html'), name='logout'),

views.py

from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.contrib.auth import login, authenticate
from django.contrib.auth.forms import UserCreationForm
#from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
#from .models import Question

memo = []
def myView(request):
    return HttpResponse('Hello, Surya!')

def myHome(request):
    return HttpResponse("This is going to be the main page.")
def home(request):
    numbers = [1,2,3,4,5]
    name = 'Jeevan Anand'

    args = {'myName': name, 'numbers': numbers}
    return render(request,'home.html',context = args)
def index(request):
    return render(request,'index.html')
def game(request):
    numbers = [1,2,3,4,5]
    name = 'Jeevan Anand'

    args = {'myName': name, 'numbers': numbers}
    return render(request,'game.html',context = args)
def main(request):
    numbers = [1,2,3,4,5]
    name = 'Jeevan Anand'

    args = {'myName': name, 'numbers': numbers}
    return render(request,'main.html',context = args)
def signup(request):
    if request.method =='POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            return redirect('http://127.0.0.1:8000/login/')
    else:
        form = UserCreationForm()
    return render(request,'hello/signup.html',{'form':form})

def login_view(request):
    if request.method =='POST':
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            #log in the user
            return redirect('articles:list')
    else:
        form = AuthenticationForm()
    return render(request,'hello/login.html',{'from':form})

0 个答案:

没有答案