Can I put one django site inside of another? - django

I started develop two sites separately, but now I need to merge them (so http://site1.com/site2) points to site2 (which has a separate settings.py).
I could probably refactor the code and make site2 an app of site1, but I suspect there is an easy way. Also, site2 uses a different database, and I don't intend to mix up both databases...
If I want to use subdomain (like site2.site1.com), will it make it easier?
Any suggestion? Thanks.

The easiest way to do this is to leave both Django applications separate but present them as one site using a reverse proxy such as nginx. The applications will live on separate servers or at least be served on the same server on separate ports, and nginx will proxy requests to one application or the other based on what path is requested.

Related

How to run multiple sites from one instance of Django?

I am using Django as the back end and Nuxt as the front end, with Postgres as the database. I would like to have different tables/databases for each domain.
The Django code and the Nuxt code will be the same for all sites.
The way the app is set up, it requires different domains to have different databases or at least different tables.
At the moment, I am thinking I need to create a separate installation of Django/Nuxt for each domain. But I am wondering if there is a better way?
Setting up different Code bases for every domain is not a good idea at all. I had an app that was set up that way and soon we were struggling to maintain the same code and DB structure for all the different domains. After a few domains, it will become tricky.
I would suggest developing a multi-tenant SAAS based app, where you can have multiple tenants running the same Django/Nuxt code but having different schemas in the Postgres, So your database for different domains will be completely separate from each other. I would suggest using django tenant schemas for this. Even if it takes you some time to set it up, I would suggest doing it. It will save a great deal of time for you in the future.

Django REST and React implementation model

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.

Subdomain hosting with Django + Nginx +Gunicorn

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.

Django - Subdomains with Middleware or Subdomains with Apache Virtual Hosts?

I'm new to Django...
I need to start a project that will have subdomains, but I'm little confused about this subject...
I will have a website serving Spain, other serving United Kingdom and other serving United States and I will use only one domain and 3 subdomains, just like this:
Main domain:
mysite.com
Subdomains:
es.mysite.com
uk.mysite.com
us.mysite.com
These 3 different site in future could have to scale, each one in one dedicated server, but for now these 3 websites will use the same server.
In a previous question I was told to use a middleware solution(http://thingsilearned.com/2009/01/05/using-subdomains-in-django/) but I don't konw if it this that I need. With this solution if I need to scale the websites for dedicated servers each one I think will not work...
It is possible to define instead the subdomains in Apache Virtual Hosts? What do you think of using 3 different Django projects with Apache Virtual Hosts will doing the job? This is a better solution or I should go with middleware?
Best Regards,
If you're looking to expand the subdomains to different servers eventually, the easier solution will probably be using virtual hosts on your web server.
Each host can just use a separate settings module (they can all import * from a common settings module, changing any database / language settings which are specific to that domain).
Deploying this way means you have a higher memory usage, since you will be dealing with separate instances for each domain, but that doesn't sound like it will be a problem for you and your long term direction. It also makes things simpler, using middleware can get messy (especially with tests and the like).

Multiple Django Sites, one server

I have multiple sites for the same client, on the same server, running django, e.g. fooplumbing.com and bazheating.org. These two sites would each have different django apps, that is the plumbing site shouldn't be able to access the heating apps, and vice versa. There are no objects shared between the two sites, and each needs its own separate admin site.
Is this possible through something like the sites framework, or would I need to have two separate apache instances running the sites? (Yes, I need to use apache - no choice)
It's a Linux server, so is there some clever way of using symlinks to do this? I'm pretty experienced with basic django development, but I have no clue when it comes to server management.
The sites framework won't help you - they should be served as completely separate WSGI applications.
But there's no need for separate Apache instances. Just configure Apache to serve separate VirtualHosts, each with its own WSGI file.