I am developing a web app using django for server-side. It has clients in android, ios and frontend. I was thinking of using subdomains for differentiating the urls of these clients. The differentiation is due to the fact that responses to urls are different for different clients.
I was hoping of being able to do using subdomains like android.example.com, ios.example.com...etc. My subdomains are fixed.
Can you help regarding what approach I should take to achieve this. Some options I have read are
Hosting two different project with same database.(Looks quite good for me, but may not be the optimum)
Hosting on same instance using sites framework.(Not sure as to how good this option is)
Hosting using virtual-host(Really Not able to understand how to achieve this).
Using a Sub-domain Middleware, as mentioned in many of answers and also in some Django Snippets.
Please help me with the best option and if possible with links to some tutorials as to how to achieve it. Thanks.
"Using the sites framework" is somehow the same as hosting two projects with the same database. If you would use the sites framework you would have seperate instances for each subdomain which share the same code base and data base, but have to differ in one setting in the first place, which is SITE_ID.
If you're able to run multiple instances this for sure has some advantages:
You don't need additional processing via a middleware
You can easily choose different settings for each site, eg. different template paths, use different middleware etc, even customize urls per project if necessary
You're doing already some kind of load-balancing, as you're directing requests to seperate instances, also if one site crashes it shouldn't affect the others
If you can only run one instance I guess your only choice is using something like a middleware, eg. django-mobile then is maybe something to look in as it offers you some good toolset for determining the type of client etc...
But besides that note that it might not always be the best practice to have seperate domains with the same content when it comes to SEO.
Related
I am currently creating a website hosted by Django. I plan to use React as my frontend framework. I have done some research on putting them together but most say that I should go for the SPA model and have separate web servers for frontend and backend. The problem is that I wish to use apache as a prod server with django and avoid having 2 separate servers. I have read about the hybrid model and having django serve static files with react.
My Biggest concern is security as I have already setup apache for security and I aware that node.js is somewhat insecure.
What would the best approach be. The separate SPA model or the hybrid model.
I'd say it's okay to go for hybrid model if the project is small and you are the only one working on it and you only want to make things done. I think it's kinda messy to create apps like this unless they don't really worth the time.
But if it's a big project and more than one developer is working on it or will work on it then i highly recommend going with separate web servers one serving frontend app and one django app.
Also note that you don't really need 2 different servers. You can use one server for both and use 2 different which is still not necessary and you can use one web server to serve both.
And security not something that different models can cause to downgrade or upgrade. It's up to you to configure the server and write both frontend and backend apps secure enough to do the work for you.
There are more than one web servers that are as secure as they can be and they work with both django and react pretty well. I used nginx many times to host both django and react apps and i had no problem causing by nginx itself whatsoever.
And for last piece of advice if you will; Creating good quality apps requires a lot of time and energy, working with different technologies that do really good for what they are made for and if you are planning to be a really good developer you should come out of your comfort zone and adapt with new technologies that comes out and they are coming out pretty rapidly which requires you to learn constantly and do things in way you are not used to yet and making things work even if they doesn't seem to be good together at the first look.
I'm learning Django/backend programming but I'm not exactly sure how to organize all of my stuff. I'm planning on having two websites with different domains, one is a personal one, and another one is for an organization.
What would be the best way to create this with Django? Would I separate this into two projects, and have all of the files in each project? Should I create an app for each section of the site? Or should I put it all under one project, and have an app for each website?
Also, as a quick side question, why do I have to run Nginx and uwsgi instead of just using Django? I don't exactly understand the difference between all these things. NginX is a proxy server, that sends requests to uwsgi, which then goes to Django, right? It seems excessive. I don't even know where to start, in terms of creating a host name router..
Thanks a lot, and if you can any good reading links/books let me know!
As a beginner you better stick with different projects for
different domain, when you gain more experience, you will find out
how much of the logic is reused in both and then make a decision of reusing the apps in single project.
Please read the section on wsgi: https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/
I'm new to Google App Engine and am trying to port my Django application to use that. I haven't been able to find too much on this and don't think multitenancy is what I'm looking for (seems to be for more or less identical apps with different data sources?), but my scenario is this:
I have multiple domains and currently have different settings file (with seperate WSGI files) which works great for my current Apache configuration, but I'm trying to migrate over to GAE and can't seem to figure out how to do something similiar based on domain name? Really, all I critically need is a seperate urls file based on the domain name (datastore is the same on both), although it would be ideal to have a separate settings file so I don't have to load unused apps, preprocessors, etc on sites that don't need them.
You can possibly have two different versions of the app, they both will use the same data store, since source code of both versions can be different, you can specify different configurations/settings for each of them.
coming to accessing different versions, you can either route through your dashboard/domain settings and/or fine tune it with help of traffic splitting
hope it helps
What I'm trying to do is best explained by looking how wordpress.com works:
each blog is assigned to a new subdomain, but users can use their own domain as well. Custom domains could be assigned using a simple web interface
each blog has its own contents, theme, etc
all blogs share the same codebase
Is it possible to do the same thing in Django?
I'm not interested in implementing subdomains, but I want the other features.
It is important to me to find a way that domains don't have to be hardcoded in a configuration file in order to work. The dynamic nature of domain assignment makes managing large number of domains possible. It would be ideal if domain matching could be done against a database table.
I use nginx and uwsgi.
Yes but it will require more work in Django compared to out-of-the box Wordpress install but will offer you more flexibility.
You might want to take a look at django sites. However I don't think it will be able to do everything you are trying to do.
A more modular system would be for you to write a script which when invoked will bootstrap a new db schema, new virtuelenv, install all necessary things into it, add a site config for the new site to nginx/apache and then restart the nginx/apache. The code can be from the same directories, except since each site will run on it's own virtualenv, it will be much more secure, reliable and fault tolerant. This however as you can see will require some work but I depending on your requirements, it is the most flexible way.
I was hoping to get some suggestions on some best approaches to develop a multi tenant Django project on Google AppEngine.
Some Thoughts to Consider.
I would assume using djnago.contrib.sites is a must.
I would like to use existing applications such as django-profiles and django-registration, I know their models would need porting.
Can multiple domains be pointed to the GAE App and the site be automatically chosen from the request headers?
IF not multiple domains, is there a way to say take a request say to www.example.com/tenantA/login and www.example.com/tenantB/login and push them to one view but with knowledge tennant without changing all the views, maybe using custom managers to hide the complexity from the views.
Generally hoping this will be a discussion of any approaches you have taken in the past or plan to take.
Looking forward to any Comments/Answers.
Regards
Mark
I can answer the App Engine questions for you, though I don't know the Django ones:
Yes, anyone can point a domain to your app using Google Apps, with the 'add services' option, entering your App ID when prompted. You can then check the 'Host' header to determine what site you want to use.
You can hide information per-tenant by using hooks to automatically insert the host in entities and queries: http://code.google.com/appengine/articles/hooks.html
Today Google released SDK 1.3.6, which includes multi-tenancy baked right into the solution.
http://googleappengine.blogspot.com/2010/08/multi-tenancy-support-high-performance_17.html