Learn to build Django web applications in minutes and deploy them to production
Brought to you by Vihar Kurama (Guest Author)
Learn to build Django web applications in minutes and deploy them to production
Brought to you by Vihar Kurama (Guest Author)
Second and last part of Django 3.0! What are your thoughts guys? Share it in the comments
@robertino.calcaterra Doesnât seem to work properly. While running locally (before Heroku steps), clicking the âLog Inâ link to bring up the login page produces an error.
File "\codeshare\auth0login\auth0backend.py", line 15, in authorization_url
return 'https://' + self.setting('DOMAIN') + '/authorize'
TypeError: can only concatenate str (not "NoneType") to str
FYI, Iâm being taken to http://localhost:8000/login/auth0/ for the login page. Not sure if thatâs correct but it doesnât feel correct. Iâve gone through every step multiple times but cannot find any mistakes in my code. Starting to think thereâs a bug in the tutorial but I am not sure where.
Hey there @pdipatrizio!
One of our Guest Authors (Vihar Kurama) wrote that blog article. We already reached out to him so either someone from the team responsible for blog or the article author himself will reach out to you soon regarding your hurdle!
Hwy @pdipatrizio, it seems like your setting("Domain")
variable is returning a "None"
type instead of your application domain. To resolve this issue, make sure you use the right values for Auth0
keys that you setup in .env
file. You can find them in the Auth0 Dashboard after creating your application. Let me know if youâre encountering any other errors. Thanks!
Hey Vihar. Thanks for the reply. I had the correct Auth0 domain and keys but it turned out my .env
file wasnât being found. Iâm still not 100% sure why but I was able to get it to work by moving the .env
into the same folder as settings.py
and calling load_dotenv()
without setting the path. I also edited the path in .gitignore
to reflect the new location. Thanks again!
No worries! Weâre here for you!
Small tip for others who may want to know how to generate their own requirements.txt. You can run pip freeze
in a terminal to get a list of packages/versions installed in your environment. Or to keep a list updated dynamically, you could use something like:
import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted([(str(i).replace(' ', '==')) for i in installed_packages], key=str.lower)
[print(i) for i in installed_packages_list]
The pip freeze
command misses a couple of packages but they may not be necessary to list as requirements. Iâm not quite sure
Thanks again for the guide!
Thanks for sharing that with the rest of community!
Pretty sure this code snippet is wrong:
# ga-django-python/codeshare/settings.py
AUTHENTICATION_BACKENDS = {
"auth0login.auth0backend.Auth0",
"django.contrib.auth.backends.ModelBackend",
}
it should be:
# ga-django-python/codeshare/settings.py
AUTHENTICATION_BACKENDS = [
"auth0login.auth0backend.Auth0",
"django.contrib.auth.backends.ModelBackend",
]
Iâm not sure if thereâs something wrong with my eyes but those two are the same.
One of them is surrounded by {} and one by . Different datatypes.
Ohh gosh! Gotchya thanks for sharing it!
Hey @mark.jones, thereâs no error in the code. According to the comment raised both the data-typeâs lists or dicts will work in the production environment. Also, all those settings were automatically generated by Django itself based on the version youâre using. Let me know if youâre still facing any problems.
Thanks
Thanks for reaching out Vihar!
Hi Vihar,
Thank you for sharing this tutorial. Unfortunately I am confused with the Login_URL thing.
I am not sure which URL I will have to mention there ? I created the app name SLMS_APP1 and you created the app - with the name auth0login
python3 manage.py startapp auth0login
I am now getting an error -
ModuleNotFoundError at /login/auth0
No module named âauth0loginâ
Request Method: GET
Request URL: http://127.0.0.1:8000/login/auth0
Django Version: 3.1
Exception Type: ModuleNotFoundError
Exception Value:
No module named âauth0loginâ
Exception Location: /Volumes/My_Personal/Programming/DJANGO/Smart_Leave_Management_system/lib/python3.8/site-packages/social_core/utils.py, line 56, in import_module
Python Executable: /Volumes/My_Personal/Programming/DJANGO/Smart_Leave_Management_system/bin/python3
Python Version: 3.8.4
Python Path:
[â/Volumes/My_Personal/Programming/DJANGO/Smart_Leave_Management_systemâ,
â/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zipâ,
â/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8â,
â/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynloadâ,
â/Volumes/My_Personal/Programming/DJANGO/Smart_Leave_Management_system/lib/python3.8/site-packagesâ]
Server time: Sat, 29 Aug 2020 21:46:52 +0000
modules installed on my environment is -
asgiref==3.2.10
certifi==2020.6.20
cffi==1.14.2
chardet==3.0.4
cryptography==3.1
defusedxml==0.7.0rc1
Django==3.1
idna==2.10
oauthlib==3.1.0
pycparser==2.20
PyJWT==1.7.1
python3-openid==3.2.0
pytz==2020.1
requests==2.24.0
requests-oauthlib==1.3.0
six==1.15.0
social-auth-app-django==4.0.0
social-auth-core==3.3.3
sqlparse==0.3.1
urllib3==1.25.10
Hello, welcome to the Auth0 Community. Thank you for reading the blog post. Iâve shared your question with the blog post author
Sorry I have resolved this. I didnât mention the .env file path in settings.py and after mentioning this it worked.
ENV_FILE = find_dotenv()
if ENV_FILE:
load_dotenv(ENV_FILE)
Perfect glad to hear that and thanks for sharing with the rest of community!
Hey @trickyj, glad youâve resolved the issue. Also make sure to add your app name in settings.py
file, in your case itâs SLMS_APP1. I also hope you figured all the URIs
and Keys
that you need to export in the .env
file. Let us know if you have any questions further.
Happy coding !