有人可以帮助我吗?加载项目时出现以下错误:
不正确地提高配置(msg.format(name = self.urlconf_name)) django.core.exceptions.ImproperlyConfigured:包含的URLconf “ siteV1.urls”似乎没有任何模式。如果你看到 文件中的有效模式,则问题可能是由 循环导入。
这是我的urls.py
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from drink.views import HomepageView, CreateDrinkView, CreateNormalDrinkView, CreateMixedDrinkView
from machine.views import SettingsView
from account.views import LoginView
urlpatterns = [
path('', HomepageView.as_view()),
path('create-drink', CreateDrinkView.as_view()),
path('create-drink/save-normal', CreateNormalDrinkView.as_view()),
path('create-drink/save-mixed', CreateMixedDrinkView.as_view()),
path('settings/', SettingsView.as_view()),
path('accounts/login/', LoginView.as_view()),
path('admin/', admin.site.urls),
]
if settings.DEBUG == True:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
else:
pass
#enter code here for media and static handeling during production
该问题似乎与LoginView的导入有关。如果删除此导入和路径,程序将运行而不会出现任何错误。我的accounts.views包含以下代码:
from django.contrib.auth import authenticate, login
from django.shortcuts import render, redirect
from django.views.generic import TemplateView
# Create your views here.
class LoginView(TemplateView):
template_name = 'login.html'
def get(self, request):
return render(request, self.template_name, {})
def post(self, request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
# Redirect to a success page.
return redirect('')
else:
# Return an 'invalid login' error message.
return render(request, self.template_name {'error': 'Gebruikersnaam of wachtwoord onjuist!'})
account.models目前为空。我尝试运行pycycle来检查循环导入。 Pycycle返回,没有发现圆形进口。非常感谢您的帮助!
答案 0 :(得分:0)
通过删除应用程序并重新创建来解决此问题。仍然不知道问题出在哪里,但是现在可以解决。