models.py alanından kendi oluşturduğum modeli import etmeye çalışıyorum fakat erişemiyorum bir türlü. sizce nasıl düzeltebilirim ?
Yani nasıl import etmeye çalıştığınızı bilmiyoruz. modelinizi bilmiyoruz. aldığınız hatayı bilmiyoruz. hiçbir şey bilmiyoruz nasıl yardımcı olabiliriz ki
doğru dedin hocam hemen hatanın olduğu dosyanın kodlarını verim
from django.shortcuts import render,redirect
from views import UserAccountInfo
from django.contrib import messages
def home(request):
return render(request, ‘index.html’)
def login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
if UserAccountInfo.objects.filter(username=username).exists():
messages.error(request,'username already exists')
else:
if UserAccountInfo.objects.filter(password=password).exists():
messages.error(request,'password already exists')
else:
return redirect('home')
return render(request, 'login_page/login.html')
def register(request):
if request.method == ‘POST’:
username = request.POST[‘username’]
password = request.POST[‘password’]
firstname = request.POST[‘firstname’]
email = request.POST[‘email’]
if UserAccountInfo.objects.filter(username=username).exists():
messages.error(request,'username already exists')
else:
if UserAccountInfo.objects.filter(password=password).exists():
messages.error(request,'password already exists')
else:
if UserAccountInfo.objects.filter(email=email).exists():
messages.error(request,'email already exists')
else:
if UserAccountInfo.objects.filter(firstname=firstname).exists():
messages.error(request,'firstname already exists')
else:
user = UserAccountInfo.objects.create_user(username=username, password=password, first_name=firstname, email=email)
user.save()
return render('login')
return render(request, 'register_page/register.html')
bu attığınız dosya views dosyası olmalı çünkü buraya viewları yazmışsınız. yani zaten views.py içerisindesiniz ama içinde olduğunuz dosyadan UserAccountInfo import etmeye çalışıyorsunuz.
from models import UserAccountInfo
yazarsanız düzelir diye tahmin ediyorum.
doğru orayı değiştirmeden atmışım. düzelttikten sonrada şu şekilde bir hata alıyorum terminalden
Exception in thread django-main-thread:
Traceback (most recent call last):
File “C:\Users\ercey\AppData\Local\Programs\Python\Python311\Lib\threading.py”, line 1038, in _bootstrap_inner
self.run()
File “C:\Users\ercey\AppData\Local\Programs\Python\Python311\Lib\threading.py”, line 975, in run
self._target(*self._args, **self._kwargs)
File “C:\django\usersPanel\venv\Lib\site-packages\django\utils\autoreload.py”, line 64, in wrapper
fn(*args, **kwargs)
File “C:\django\usersPanel\venv\Lib\site-packages\django\core\management\commands\runserver.py”, line 134, in inner_run
self.check(display_num_errors=True)
File “C:\django\usersPanel\venv\Lib\site-packages\django\core\management\base.py”, line 486, in check
all_issues = checks.run_checks(
^^^^^^^^^^^^^^^^^^
File “C:\django\usersPanel\venv\Lib\site-packages\django\core\checks\registry.py”, line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\django\usersPanel\venv\Lib\site-packages\django\core\checks\urls.py”, line 44, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\django\usersPanel\venv\Lib\site-packages\django\core\checks\urls.py”, line 63, in load_all_namespaces
url_patterns = getattr(resolver, “url_patterns”, [])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\django\usersPanel\venv\Lib\site-packages\django\utils\functional.py”, line 47, in get
res = instance.dict[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File “C:\django\usersPanel\venv\Lib\site-packages\django\urls\resolvers.py”, line 718, in url_patterns
patterns = getattr(self.urlconf_module, “urlpatterns”, self.urlconf_module)
^^^^^^^^^^^^^^^^^^^
File “C:\django\usersPanel\venv\Lib\site-packages\django\utils\functional.py”, line 47, in get
res = instance.dict[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File “C:\django\usersPanel\venv\Lib\site-packages\django\urls\resolvers.py”, line 711, in urlconf_module
return import_module(self.urlconf_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ercey\AppData\Local\Programs\Python\Python311\Lib\importlib_init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 1204, in _gcd_import
File “”, line 1176, in _find_and_load
File “”, line 1147, in _find_and_load_unlocked
File “”, line 690, in _load_unlocked
File “”, line 940, in exec_module
File “”, line 241, in _call_with_frames_removed
File “C:\django\usersPanel\blog\blog\urls.py”, line 19, in
from .views import home,login,register
File “C:\django\usersPanel\blog\blog\views.py”, line 2, in
from models import UserAccountInfo
ModuleNotFoundError: No module named ‘models’
tamamdır hatayı çözdüm