Django multi host url configuration per app - python

I searched around here on SO for how I would setup different domains for apps within a single django project. e.g.: news.io, jobs.io, etc for a news, job, etc app within the main project.
The app will also have authentication where the user will need to remain signed in across the domains if this matters. e.g. - billing platforms, etc.
The recommendation was to use a MultiHostMiddleware found here which is obviously outdated.
Similarly, the other recommendation was to use django-multihost which is also really old.
I'm on Django 1.11 and Python 3.6. Is there anything more recent or better yet how would I roll my own?

I'm just getting into this myself, and from what I can tell django-tenant-schemas seems to be the best option.

Related

Connecting 2 Django Projects on Different Servers

For reasons out of my control, 2 Django projects were placed on 2 different AWS servers, both using the same RDS AWS database.
I want Project B to be able to access and manipulate the models (tables) used in Project A (where they were originally created).
Is this at all possible? Importing the Project A app over the network via the PYTHONPATH in some way?
Sorry...I lack the reputation to comment otherwise I would not have posted.
I think in this situation, you may need to make use of the Django REST Framework.
This way you can simple authorize the projects to talk to each other, DRF comes with httpbasic built in, but you probably should try to set up some type of hashed token as part of the auth.
I found this guide recently...although it's specific to mobile devices, it's probably one of the better walkthroughs of the DRF.

Configuring multi-tenancy

In a local dev env, I'm currently attempting to hack my way to multi-tenancy using Mezzanine:
Mezzanine makes use of Django’s sites app to support multiple sites in a single project. This functionality is always “turned on” in Mezzanine:
That's pretty much as far as an entry-level tut for multi-tenancy on mezzanine gets. Great, so I go to the admin site, and add a site:
Domain name-----|----Display name
127.0.0.1:8000----|----English Site
127.0.0.1:8000/es|----Spanish Site
Now, I am stuck. I have fiddled around with url.py, but figured that's not where to start, considering I need to know something to map the url to. Views? Lost.
Any ideas?
(Included translation is not an option given the web service will never translate as good as a human.)
Multitenancy in mezzanine is done via domain names. You will need to run http://dev.site and http://esdev.site or similar in development (add the entries to your hosts file and make sure they match the listings in the sites part of admin).
In production you'll also want to use two different domains too.
For example, my personal site http://dpn.name/ and my business site http://behest.com.au/ are both running off the same mezzanine install.
Later on when you have the right setup, you'll be able to add new posts and pages to each specific site by either logging into the admin via each domain name, or changing the currently active site in the admin (the drop down is in the top right if you have multiple sites set up)
Hope that helps, please let me know if you need more info.

What exactly are Django Apps

I want to switch from Rails to Django, to broaden my mind, and a question has bobbed up in my mind.
My Rails app is quite a mess, since my hobby-based development approach is a patch-and-glue one. I have seen very early that Django divied between a project and an app. According to their site, a project is made of many apps, and one app can be used for many projects.
This intrigued me, since that would made the lines between my site's areas clearer. I tried to find some more examples and information on that, but I couldn't answer my question, which is:
How big/small is such an app? Are they able/supposed to interact closely?
It is, for example smart to have one app to deal with user's profiles, and another app to deal with blog-posts and comments, from those users? (In my site, a user can have several blogs, with different profiles). Or are they meant to be used otherwise?
A django App is a fancy name for a python package. Really, that's it. The only thing that would distinguish a django app from other python packages is that it makes sense for it to appear in the INSTALLED_APPS list in settings.py, because it contains things like templates, models, or other features that can be auto-discovered by other django features.
A good django app will do just one thing, do it well, and not be tightly coupled to any other app that might use it. A wide variety of apps are provided with django in the contrib namespace that follow this convention.
In your example, a good way to devise apps is to have one for user profiles (or use one of the many existing profile apps), one app for blog posts (or one of the many that already do this), one app for comments, separate from blog posts (again, you can use an existing app for this), and finally, a very tiny app that ties the three together, since they don't and shouldn't depend on each other directly.
The purpose of using app's is to make them reusable. Django likes DRY principle DRY stands for DO NOT repeat yourself
An app should be as small as it can, and loosely coupled. So, for an app should not need another app to work properly.
Django recommends writing an app for each table (well, not always, but as soon as you want to grow your app, you will definitely need to divide tables to pair apps. Or else you will have hard time for maintaining your code.)
You can, for example, create an app for users, an app for sales, an app for comments, an app for articles. It will be easier to maintain your code and if you have done it right, you can use the app in other project with a little (if any) modification in the app.
Project's are, compilation of app's. Users app, articles app, comments app can come together an make a project, or in other words, a website.
If you want to learn django, I suggest you to check out:
http://www.djangobook.com/
http://docs.djangoproject.com/
One word of advice, do not, in any case, copy/paste. Not only your code has great chance to fail, but you will not know what the code is doing. If you are going to use someone elses code in your project, at least type them, this will make you understand what the code is doing, or at least, it will give an idea.
Writing your own code is always better for maintance, but this does not mean that you should reinvent the world, you can use libraries, look at their documentation to use it properly.
Documentations, tutorials are you best friend.
Good luck.
A project is basically a place where your project lives...in your project you setup your url's, project settings, etc.
An app defines its own data models and views to be used within a project. You can move these between projects if you like.
I highly recommend running through the tutorials from the Django site as they will show you what a project and app are, how to manage both, how to use the admin panel, how to make the app usable in multiple projects, etc.
A portal = A django project
A ads system, gallery photos, catalog of products = Apps

Data Driven Framework: Web/Desktop Camelot V Django etc

Wanting to get some feedback on frameworks. Web/Desktop. It doesn't seem to be much difference in most respects expect web can go everywhere and desktop can't.
For a small user base however using database database driven application, where 70% input would come from files, and 30% for the user. Would I get more benefit from a desktop based solution like Camelot Camelot or Dabo & Pyjamas matched against say Django, Grok, Plone or Pyramid?
I was going to learn django based largely on docs Django Book and apparent ease of learning. Thought i should check first before diving in if its the most appropriate.
For data driven project where display/input/reporting facilites(charts/graphs) required is there a best fit or a "better fit". Can't see that I would loose anything by using a web framework for this these days, but where the desired output is more "business" logic based rather than a web page which avenue should i go web v desktop and if either better option?
Edit: I have found another possible solution/answer web2py web2py
I think you'll find web2py very easy to learn and use. Note, if desired, you can easily distribute your web2py app to individual users for installation on their own computer like a desktop app (using the browser as the user interface) -- see here. The users don't need to have anything else installed on their computer (not even Python), and web2py itself doesn't require installation, just unzipping.

How to get Django to work on Apache in Windows?

I'm creating an internet radio station site on my Apache, and I've decided Django is the CMS which is best suited to the task.
http://www.gareth53.co.uk/work.html mentions it being used for radio station sites, and I decided I'd go with this since it seems to be a fairly popular choice.
These are some examples of it in action on live sites:
http://www.capitalfm.com/on-air/station-schedule/
http://www.heart.co.uk/suffolk/shows/
I'm aware I need python and mod_wsgi to get it to run, but how do I ensure it works properly on an Apache server? (I'm on Vista Home Edition, and this is just a test/development site until it works properly).
I want my schedules page to look similar to this CMS:
http://www.trentfm.co.uk/schedule.asp
(the effect I'm trying to emulate, in design terms).
I'm aware I'd have to create templates from reading the Django manual, and it uses SQLite, but I'm fairly new to Django and it would be a useful skill to learn.
Obviously that site uses IIS, which I'm not using, but the design is what I am intending to create a homage to (under copyright law a parody etc. is permissible under fair use - the station names are different, though).
My site is different, but the same basic model applies as seen in the stations above.
What has been your experience of using Django and would you recommend it as a CMS?
First of all, Django is not a CMS.. it is a web framework. You can find how to deploy django with apache and modwsgi in the following link.
http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

Categories