No video

Django Multi Tenant Tutorial Using Subdomains - Basic Implementation

  Рет қаралды 25,728

Code With Stein

Code With Stein

Күн бұрын

Learn how to implement multi tenancy using Django with the use of subdomains.
The tenants will share the same database, but I separate them using subdomains. I test it locally by using the hosts file on my mac.
If you want to test this your self, you can add "fake" domains to your hosts file on your computer.
---
Support me
Donate: www.paypal.com...
Patreon: / codewithstein
Merch: shop.spreadshi...
Important links
Discord: / discord
Twitter: / codewithstein
Website: codewithstein.com
---
#codewithstein #django #multitenants #multitenant #python #learndjango

Пікірлер: 123
@dynarielinnovations6361
@dynarielinnovations6361 3 жыл бұрын
whaooo .... this is awesome
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you 😁😁
@lyricdakota6174
@lyricdakota6174 3 жыл бұрын
InstaBlaster...
@MrAverageViewer
@MrAverageViewer 3 жыл бұрын
Multi-Tenant applications are a great topic for Django!! Thanks for creating & posting this video!!
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you so much Michael 👍🏻😁
@djangodeveloper07
@djangodeveloper07 3 жыл бұрын
bravo. no extra talk. you are here to learn then take it directly. what a tough topic delivered in such a easy way. Thank you
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you so much for the feedback :-D
@twattusbobble9845
@twattusbobble9845 Жыл бұрын
I have no idea why you don't get 100s of 1000's of views Stein. Your explanations are soooooooo clear!
@CodeWithStein
@CodeWithStein 9 ай бұрын
Thanks ☺️ me neither 🤷🏼‍♂️
@mattfreire
@mattfreire 3 жыл бұрын
Awesome tutorial!
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you 😃😃
@AcademyOmen
@AcademyOmen 3 жыл бұрын
Hihi.. from JustDjango himself 😏😊
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Yes, he’s a great dude ☺️
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you 😁
@ahlalfiqh
@ahlalfiqh 3 жыл бұрын
@@CodeWithStein Tutorials of JustDjango and Code With Stein are a great contribution to Django community. Thanks for this treasure. My comment got deleted by KZbin, dunno why!
@lollers2009
@lollers2009 3 жыл бұрын
Great video, I've passed it as a variable previously but much cleaner this way!
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thanks 😃 yes, there is many ways to solve it 👍🏻
@IllevensKO
@IllevensKO 3 жыл бұрын
incredibly helpful. Thank you Stein, may you live a happy life!
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you so much :-D I'm glad you liked it :-D
@IllevensKO
@IllevensKO 3 жыл бұрын
@@CodeWithStein hey do any projects on this channel include multi tenancy?
@IllevensKO
@IllevensKO 3 жыл бұрын
@@CodeWithStein also at 01:53 you say that you setup example to point to localhost - how did you do that ?
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Hi, not multi tenancy the way I have done it here no :/ just with regular foreignkeys on the time tracking saas tutorial 👍🏻
@CodeWithStein
@CodeWithStein 3 жыл бұрын
I Edit my hosts file. Both Windows and Mac has this. And then I point «fake» domain names to 127.0.0.1 👍🏻
@lolaswift111
@lolaswift111 2 жыл бұрын
This is awesome. You content is unique and so much valuable. thank you stein.
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Thank you so much :-D
@idowujulius761
@idowujulius761 3 жыл бұрын
Thanks this is very great !
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you :-D
@piukul
@piukul 3 жыл бұрын
This is really useful!
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you :-D
@dynarielinnovations6361
@dynarielinnovations6361 3 жыл бұрын
yeah am i tto learn from master developer.. have been very busy working on the e commerce class you thought us. its a great e commerce site with almost 1500 products right now to be relaunch soon
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Great, looking forward to see it 😃😃
@timniets8584
@timniets8584 3 жыл бұрын
Nice video Stein!
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you 😁😁
@amenabe9842
@amenabe9842 3 жыл бұрын
Loved it Thanks !!
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thanks 😁😁
@yanirhaim7787
@yanirhaim7787 3 жыл бұрын
Great Tutorial!
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you Yanir :-D
@vishalparkar
@vishalparkar 2 жыл бұрын
Thanks a ton, Stein ! Keep up the good work !
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Thanks, I will 😁
@jason_m2003
@jason_m2003 3 жыл бұрын
Very cool video!
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you Jason 😃😃
@nurbektaizhanov4534
@nurbektaizhanov4534 3 жыл бұрын
Great video! I am from reddit .
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you 😁 welcome, I hope you liked the content 👍🏻
@puchesjr07
@puchesjr07 3 жыл бұрын
You will want to add a unique index to the subdomain or you could have issues with multiple parties attempting to register the same subdomain.
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Hi, that’s a good point! I didn’t think about it when I created the video :/
@fblumescobar
@fblumescobar 2 ай бұрын
1st of all, thankyou!! Is this for single schema multitenancy or multiple schema multi tenancy?
@RegisdoPython
@RegisdoPython 2 жыл бұрын
Very good. Thanks.
@CodeWithStein
@CodeWithStein 2 жыл бұрын
You’re welcome 😁 long time no see btw 😁
@Senpaismiles
@Senpaismiles 3 жыл бұрын
really useful and simple
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thanks 👍🏻😁
@sazidahmed3012
@sazidahmed3012 3 жыл бұрын
Awesome, New Playlist
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Yeah, thank you 😀😀
@LiaAdzumi
@LiaAdzumi 3 жыл бұрын
Hi, Great example. Please create a real world tenant app. Please do so ... Thanks. Br, I am Nyoman, form Bali, Indonesia
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Hi! Thank you, I will some day. I just have a few videos I need to make first 😉 wow, that is far away from cold Norway 😁😁
@VinamraVj
@VinamraVj 3 жыл бұрын
Awesome Tutorial, just wanted to know how to assign the tenant in view while registering user? i really am stuck with it.
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thanks :-D It's a bit too much to explain here in the comment section. But you basically just need to create a userprofile model (or a team model) where you assign a subdomain. And then in the function where you register the user, you add the subdomain as well :-)
@shadrackdanford5533
@shadrackdanford5533 3 жыл бұрын
Greetings all the way from Tanzania Is this shared table multitenancy architecture? How do you handle tenant logic in practical app? Say you are building platform such as ZohoCMS where by multiple organization might has different data? How do you optimize ORM queries?
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Hi, that's a long way from Norway :-D Yes, that is correct. All the tenants share the same database/tables. You can use this code in any types of django app, it will help you separate the data. Optimizing queries can be done in many different ways. The most used are functions like select_related and prefetch_related. These are used to implement joins. I suggest that you take a look at Django Toolbar, this is really helpful when it comes to optimization :-)
@inouguys8136
@inouguys8136 3 жыл бұрын
how to add a home/index page to this project, 127.0.0.1:8000, for home page, and subdomains for tenants. Is it possible?
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Hi, that’s possible 👍🏻 I don’t have the code here now. You probably just need to add the view like you normally do, and don’t include the url check I added in the video 😉
@lohith1399
@lohith1399 3 жыл бұрын
is it possible to add social auth to login into different schemas with different emails????
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Hi, I think so yes. But I haven’t done it my self. You can try to read a little bit about Djoser. This is a django package ☺️
@rayanali9737
@rayanali9737 2 ай бұрын
how would i automate the updating of hosts file @ 10:53 ?
@CodeWithStein
@CodeWithStein Ай бұрын
Hey, you can use some sort of python or similar to update the files automatically when a user sign up :-)
@rayanali9737
@rayanali9737 Ай бұрын
@@CodeWithStein ok sir
@softservemedia6543
@softservemedia6543 3 жыл бұрын
@Stein excellent share thank you! I've [relatively new with Django] been searching for a m'tenant solution for my app for some time. Ive tried various django packages. The app requires the tenant to access both template end and admin end. The app uses custom user setup. Using the subdomain approach, will the tenant admin also be separated? If so, will I need a superuser per tenant? [which is ok for me].
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thank you :-) The admin will not be separated, but it can be. If you check out this link (books.agiliq.com/projects/django-multi-tenant/en/latest/shared-database-shared-schema.html) at the bottom of the page. There is a little code snippet you can use to separate the admins :-)
@softservemedia6543
@softservemedia6543 3 жыл бұрын
@@CodeWithStein Thank you again! :) ... I tried the link but its broken I think ... but its okay I shall access the Agiliq book. Another thought ... How about using your subdomain concept to set the "default" database to a tenant specific database [suee Ill have to migrate many times :)] ... or database[default].schema[tenant specific] in settings.py ... possible[?] ... just to explain a little more : my app will have maximum 50 or so tenants with each tenant having around [max] 200 users .... amount of users will range from 15 to about 200.
@lolaswift111
@lolaswift111 2 жыл бұрын
@@CodeWithStein hi stein, the link is broken.
@Alex-3XL
@Alex-3XL 2 жыл бұрын
@@CodeWithStein Hi! Would you mind checking the link and update to a working one? Thanks!
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Try this one: books.agiliq.com/projects/django-multi-tenant/en/latest/shared-database-shared-schema.html
@Leperegrin
@Leperegrin 2 жыл бұрын
thanks for this...what IDE do you use? it seems fast and cool
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Hey, I’m using visual studio code ☺️
@nikunjdhawan1
@nikunjdhawan1 Жыл бұрын
how can use it with allauth?
@CodeWithStein
@CodeWithStein Жыл бұрын
Not sure, haven’t used that for a long time 🤷🏼‍♂️
@Harsh-fd4ml
@Harsh-fd4ml 3 жыл бұрын
Bro what font family you use in your vs code?
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Hmm, I haven’t changed any settings. So the default one I would think, but I don’t know what it’s called:/
@feixue7752
@feixue7752 2 жыл бұрын
do you have course on seperate the database for different tenant?
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Hi, no I don't. I have thought about making more content with multiple tenants. But I haven't had the time to do it yet :S
@marcelomilan3169
@marcelomilan3169 Жыл бұрын
do you have the github about this example?? thanks
@CodeWithStein
@CodeWithStein Жыл бұрын
No, sorry :/
@helio4327
@helio4327 3 жыл бұрын
Incrível muito bom.
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thanks :-D
@blabla-kk8bl
@blabla-kk8bl 2 жыл бұрын
What is advantages of this ?
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Hey, it makes it easier to separate teams and similar from each other. Typically used for SaaS 😉
@sanjaykrishnan8379
@sanjaykrishnan8379 2 жыл бұрын
I loved this approach. But I am still confused, which is better..single schema filtered data like you showed or having multi schema for each tenant?
@CodeWithStein
@CodeWithStein 2 жыл бұрын
It depends on the Security. Some types of applications requires a higher level of security. And the more secure you want it, the more separated you need it ☺️
@dynarielinnovations6361
@dynarielinnovations6361 3 жыл бұрын
can we use this to create a multiple vendors for an e commerce?
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Yes and no. It might be a cool way to separate their login, but I’m not going to use this in the series I am making 😉
@dynarielinnovations6361
@dynarielinnovations6361 3 жыл бұрын
@@CodeWithStein ok sir
@TheGoggs
@TheGoggs 3 жыл бұрын
Just curious as to why you wouldn't use the django sites framework for this?
@CodeWithStein
@CodeWithStein 3 жыл бұрын
I don’t have much experience with the sites framework, but could you achieve the same with it?
@TheGoggs
@TheGoggs 3 жыл бұрын
@@CodeWithStein Yeah, the model is pretty much the same as what you did. And has a similar helper function for determining the active "tenant". docs.djangoproject.com/en/3.1/ref/contrib/sites/
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Thanks, I will take a closer look 👍🏻
@pedlezelnip
@pedlezelnip 3 жыл бұрын
@@TheGoggs I don't think that's quite the same: sites seems like it's for sharing data between multiple sites, whereas multitenancy is all about completely isolating multiple sites from each other.
@johnjim3741
@johnjim3741 2 жыл бұрын
Great tutorial. I am stuck on multiple types of tenants could you help? It's not getting the tenant type and the public schema is not pointing to a url for some reason
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Hi! Hard to say whats wrong without looking at your code :S Have you fixed this now?
@nishantshrestha1760
@nishantshrestha1760 3 жыл бұрын
I wanted to ask what the correct path is to master django
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Just keep practicing and building 😉I might do a video on this subject 👍🏻👍🏻
@nishantshrestha1760
@nishantshrestha1760 3 жыл бұрын
@@CodeWithStein It would be great because most of the beginners like me will stop learning after learning the basics or just keep practising that basic part only.
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Absolutely! I see what you mean. I have added the idea to my list and will most likely make this video soon ;-)
@nishantshrestha1760
@nishantshrestha1760 3 жыл бұрын
@@CodeWithStein thank you so much. hope to see that soon
@johnjim3741
@johnjim3741 2 жыл бұрын
Can you show us a multiple type version of tenants
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Good question. I have thought about making a bit more advanced video on this subject, I just haven't had time yet :S
@Destos
@Destos 3 жыл бұрын
Why not just extend the built-in Django sites framework?
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Hi Patrick! i haven’t really used the sites framework so much. Can you give the users separate logins based on the subdomain and similar?
@Destos
@Destos 3 жыл бұрын
@@CodeWithStein from what I remember it is very similar to what you’ve done in the video with many helpers. Nothing wrong with re-implementing for learning or alternative use cases of course! I’ll actually attempt using it again for a personal project.
@CodeWithStein
@CodeWithStein 3 жыл бұрын
Hmm, which movie are you meaning? I try to do same things, but in different ways sometimes. But I can’t remember doing anything similar to this ☺️
@joshua5617
@joshua5617 2 жыл бұрын
Is this how Shopify works?
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Hi, this is a very basic version of that yes ☺️
@andreyshevchenko5925
@andreyshevchenko5925 3 жыл бұрын
+
@CodeWithStein
@CodeWithStein 2 жыл бұрын
☺️
@b_c_ab_c_a2206
@b_c_ab_c_a2206 2 жыл бұрын
when running this command -> "python manage.py runserver example.com:8000" getting below error Error: That IP address can't be assigned.
@CodeWithStein
@CodeWithStein 2 жыл бұрын
Hey, i think its a Windows problem, but I’m not sure :/
@user-hr3mh4ji3r
@user-hr3mh4ji3r 10 ай бұрын
return request.get_host().split(':')[0].lower() AttributeError: 'GetMembers' object has no attribute 'get_host'
@CodeWithStein
@CodeWithStein 8 ай бұрын
Hmm, that looks weird. Were you able to solve this?
Django and Htmx Todo Application | Tailwind CSS
25:33
Code With Stein
Рет қаралды 25 М.
How to get Django Tenants up and running
27:12
Tom's Python and Django
Рет қаралды 20 М.
Cute kitty gadgets 💛
00:24
TheSoul Music Family
Рет қаралды 8 МЛН
КАКУЮ ДВЕРЬ ВЫБРАТЬ? 😂 #Shorts
00:45
НУБАСТЕР
Рет қаралды 3,4 МЛН
小丑把天使丢游泳池里#short #angel #clown
00:15
Super Beauty team
Рет қаралды 46 МЛН
123 GO! Houseによる偽の舌ドッキリ 😂👅
00:20
123 GO! HOUSE Japanese
Рет қаралды 6 МЛН
Multi-tenant Architecture for SaaS
11:07
CodeOpinion
Рет қаралды 112 М.
Multitenancy Explained
3:01
IBM Technology
Рет қаралды 85 М.
Laravel 11: Multi-Tenancy with Multiple Databases
8:23
Laravel Daily
Рет қаралды 16 М.
You are using useFetch WRONG! (I hope you don't)
11:14
Alexander Lichter
Рет қаралды 25 М.
Custom User Model | Explore Django
14:01
Code With Stein
Рет қаралды 36 М.
Cute kitty gadgets 💛
00:24
TheSoul Music Family
Рет қаралды 8 МЛН