So here I wanted to use the Django OR with Tkinter for a school project. I can ACCESS the database from a tkinter window, it is not the problem. When I want to retrieve the value of an Entry, it puts me 'NoneType' object Has No attribute 'get'.
import os
import sys
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
os.environ['DJANGO_SETTINGS_MODULE'] = 'Journal.settings'
from tkinter import *
from blog.models import *
def connexion():
try:
user = User.objects.get(username=userEntry.get())
if user.check_password(pwdEntry.get()) == True:
windows.messagebox.showinfo('Connexion', 'You are connected')
else:
windows.messagebox.showwarning('Warning', "The password is invalid")
except User.DoesNotExist:
windows.messagebox.showwarning('Warning', "The username does not exist")
windows = Tk()
Connexion = Frame(windows, bg="white")
Connexion.pack(side=TOP, padx=5, pady=5)
Bouton = Frame(windows, bg="white")
Bouton.pack(side=BOTTOM, padx=5, pady=5)
userLabel = Label(Connexion, text="Username:").pack(padx=5, pady=5)
userEntry = Entry(Connexion, width=15).pack()
pwdLabel = Label(Connexion, text="Password:").pack(padx=5, pady=5)
pwdEntry = Entry(Connexion, width=15, show="*").pack()
quitBouton = Button(Bouton, text="Fermer", command=windows.quit).pack(side=RIGHT, padx=5, pady=5)
connexionBouton = Button(Bouton, text="Connexion", command=connexion).pack(side=LEFT, padx=5, pady=5)
windows.mainloop()
L'erreur
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1533, in __call__
return self.func(*args)
File "/Users/saikouah/Documents/Journal/Tkinter Interface/interface.py", line 13, in connexion
user = User.objects.get(username=userEntry.get())
AttributeError: 'NoneType' object has no attribute 'get'