WEstagram Login Errors
While programming the signup and login features of WEstagram (Instagram clone project), I kept bumping into the same few errors. To avoid making the same mistakes again, here's a brief summary of each error I encountered and why these error exceptions are raised.
404 Not Found: 😡
If the URL in user/urls.py doesn't match the path specificed in the HTTP request, then a 404 Not Found error is raised.
KeyError: 🤬
If a key from the HTTP request is missing or is incorrect (i.e. typo), then a KeyError is raised. Communication between frontend and backend teams is crucial for a program to work! Both frontend and backend teams have to be on the same page on which keys to send and how the keys are spelled (down to the very. last. letter).
TypeError: 🥵
I encountered this error while encoding and decoding hashed passwords in the database. When you're checking whether a password is valid or not using bcrypt or other libraries, you have to make sure that the passwords are the same type. Otherwise, a TypeError is raised. A TypeError is a standard python exception that is raised when an operation is performed on an unsupported object. For example, if I try to run a for loop on an int type, python would raise a TypeError ('int' object is not iterable). I encountered this error while using the bcrypt.checkpw() feature to authenticate user logins. For the bcrypt.checkpw() method to operate successfully, the given passwords (password from request body and password from database) must both be encoded in bytes. Otherwise, a Typeerror is raised.
Few other things to note (지훈 멘토님 감사합니다~):
try:
data = json.load(request.body)
except:
-
It's good practice to include a try/except block when pulling data from the body of a request, since a body may not necessarily be sent with the request every time
-
Decorators... Decorators are usually used for login/user verification. Since a Django project usually has multiple apps, it would be repetitive to include the same code in different views.py files to authenticate users. To avoid using repetitive code, use a decorator (stored in a different file, such as utils.py) that saves user info in the variable request.user. Honestly, I don't completely understand this concept yet, so we'll see what exactly decorators are needed for once we get started on projects 😅
Author And Source
이 문제에 관하여(WEstagram Login Errors), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@markkimjr/WEstagram-Login-Errors저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)