Multi-tenant SAAS in Django - python

I have developed Multi-tenant SAAS apps in PHP/Laravel but recently I had a challenge to develop one in Django/Python. I am still learning Django though and I really like Django rest framework (DRF). But I have difficulties to figure out the highlighted areas below, If someone shows some light, I will be good to go:
How to handle subdomains/domains and selecting the right tenant db
How to manage and dynamically handle different database in django
Can multi-tenant apps backend still be managed from Django admin interface
I will be using queues and other apps scalling techniques, need tips and tricks if any
Any example out there
Any challenge experience when developing SAAS through Django

Well...
django-subdomains
There are people who asked in SO questions about dynamic databases in django (including, ahem... me). I'm not entirely sure I understood what you mean by "dynamically handle different database" so I guess just go to the links I just mentioned and pick out the best one for your project. (also - perhaps this is more relevant?)
Check out django-multitenant-schemas and this answer too.
There was a video of the guys behind Disqus (one of the largest django app in the world) explaining how they handle scaling. Here another interesting article on the subject. Also, the legendary SO question Does Django Scale.
(and 6.) Check out this answer
I hope that's detailed enough. I know this might be a disappointing only-links answer, but this is the reality of it - Django is a newer framework, and web development with python is still less common than php. With that in mind, understand that for all the awesomness of django (and it is awesome), with more complex needs there's more you'll have to do yourself.
In this case, you'll have to figure out how to do each part of the way seperatly and then combine it all. You can easily find a way to create a REST django app for example, but then you'll need to figure out how to combine it with another package (such as the above subdomains).
You can find a million examples out there of people doing freaky things with django. It's really powerful (when I learned about dynamic models I was blown away). But the more complex your app, the more you'll need to do yourself.
Pick it up, one step at a time, and come back to SO with specific issues you're having (or the django users google group). Good luck!

Related

Using custom python classes alongside Django app

In a school project, my team and I have to create a shopping website with a very specific server-side architecture. We agreed to use python and turned ourselves towards Django since it seemed to offer more functionalities than other possible frameworks. Be aware that none of us ever used Django in the past. We aren't masters at deploying application on the web either (we are all learning).
Here's my problem: two weeks in the project, our teacher told us that we were not allowed to use any ORM. To me, this meant bye bye to Django models and that we have to create everything on our own.
Here are my questions: as we already have created all our python classes, is there any way for us to use them alongside our Django app? I have not seen any example online of people using their own python classes within a Django app. If it were possible, where should we instantiate all our objects? Would it be easier to just go with another framework (I am thinking about Flask). Am I just missing important information about how Django works and asking a dumb question?
We have 4 weeks completed and 6 more to go before finishing our project. I often see online "use Flask before using Django" since it is simpler to use. We decided on Django because in the project description, Django was recommended but not Flask.
Thanks for the help.
Without being an absolute Django expert, here is my opinion.
The Django ORM is far from being the only feature this Framework has to offer (URLs routing, test client, user sessions variables, etc.), but surely it is one the main component you want to use while working with Django since it is often directly linked to other core features of Django.
If using the ORM is completely forbidden, a lot of features out of the box won't be available for you. One of the main features I can think about is the admin interface. You won't be able to use it if the ORM is not an option for you.
So, in my opinion, you should go for another Framework like Flask. Mainly because without using the ORM, some of the Django value is gone.
Hope it helps!

Python frameworks for developing facebook apps

I'd like to ask you about your experiences in developing facebook applications in Python. Which of the popular web frameworks for this language you think best suits this purpose? I know "best" is a very subjective word, so I'm specifically interested in the following:
Most reusable libraries. For example one might want to automatically create accounts for new logged in facebook users, but at the same time provide an alternative username + password logging functionality. I need authentication to fit into this nicely.
Facebook applications tend to differ from CMS-like sites. They are action intensive. For more complicated use-cases, usually some kind of caching for the data fetched from Open Graph API is required in order to be able to perform some queries on local and facebook data at once (for example join some tables based on friendship relation).
I'd definitely prefer popular solutions. They just seem to be much more stable and better thought through. I've previously developed a facebook application in Grails and I as much as I liked the architecture and the general ideas, the amount of bugs and complication that I ran into was just a little bit too much. Also Groovy is still quite an exotic language to develop in, and this time I'm not going to work on my own.
I'm not new to Python, but definitely new to web development in Python. Though after the experience with Grails and all its twists and turns I doubt Python could really scare me.
I would almost undoubtedly go with Django as the easiest and most popular framework for developing any type of web applications, if there's a need for a full-stack framework.
Specifically, in regards to Django's app universe, it is plentiful with many active applications -- but that has its downfalls too. There's no standard application for any 'one' thing, but there are a few applications that will do basically 90% of all that's needed. Sometimes the code is poorly written, but most of the time, the apps work and do what they are needed to do, so there's almost no need for someone to dive right in to the code.
Narrowing down our options, I have had great luck with Omab's Django-Social-Auth, which was absolutely a snap to integrate. It required 3 variables in my settings.py and I was up and running.
The only issue might be if you do not want to use the django.contrib.auth.User model, but, if you are not thinking about using that, I would think about that decision twice :)
To narrow it down even further, pyfacebook is another option for integrating Facebook. It comes with a djangofb application so it's just drop, add to settings.py and all is well. It even comes with an example Django application as part of the distribution. I've had pretty good luck with this application, but, I still think Omab's much easier to integrate.
Finally, Facebook's own python-sdk is easy to integrate from a raw standpoint, where they just give you access to their APIs using a simple Python API. However, it seems to cater more to the AppEngine folks, so YMMV.
I've used Django for quite some time. As of late I use Jinja2 instead. No particular reason, but it's another option
If you do not want to start on Django now. Try learning Flask(which is comparatively a lot easier to begin than Django) and then start building app with Flask.

Designing a web based game that would run in a browser - Where should I start?

I would like to design a web based game preferably in Python ( using Django maybe) though I'm open to any language other than Java/Flash/ActionScript. The idea I have in mind is more about data models than graphics and will leverage social networking sites. I would like to extend it with a mobile web interface in the future. Please give your invaluable suggestions and recommend some resources with which I can get started.
Step 1. Design a good game.
Step 2. Be sure that it fits the HTTP model of simple request/reply GET/POST processing. Be sure that the game is still good. Some people try to do "real time" or "push" or other things that don't fit the model well and require lots of sophisticated GUI on the desktop.
Step 3. Find a web framework. Django is okay. Others are good too.
Learn the web framework. Don't start with your game. Start with the tutorials.
Step 4. Rethink your game. Be sure that it fits the framework's model, as well as the HTTP model. Be sure that the game is still good. In particular, if your focus is "more about data models than graphics" then you have to really be sure that your game's data model fits your framework's capabilities.
Step 5. Rethink your framework. Is Django still the right choice? Perhaps you need to go back to step 3 and learn another framework. There's nothing wrong with learning a second framework. Indeed, until you learn another framework, you won't fully get Django.
Step 6. Now you should have enough background to actually implement your game.
If you are considering using Django as your framework, here are just some basic points about it you might find helpful to consider:
Firstly, the Django libraries are written in Python. Therefore, at least a basic knowledge of python is required to develop a site using Django.
Secondly, Django includes its own template system that is useful for integrating with html - http://docs.djangoproject.com/en/dev/topics/templates/ .
Thridly, as you've stated that you are more concerned with data models (which I am assuming means you are going to want to store information in some way especially considering it is related to social networking ?) Django also provides for a way to integrate with databases like MySQL and SQLite and the tutorial even walks you through how to set one up if you haven't already - http://www.djangobook.com/en/2.0/chapter05/ - and how to integrate with a legacy database if you have - http://docs.djangoproject.com/en/dev/howto/legacy-databases/?from=olddocs .
Lastly, Django enables you to run your site off of their development server which can be really useful for testing and running your site locally before deploying it to the web via Apache or another web server of your choosing - http://docs.djangoproject.com/en/dev/intro/tutorial01/#the-development-server .
I would really encourage you to do the online tutorial - http://docs.djangoproject.com/en/dev/intro/ - or take a look at Holovaty and Moss's "The Definitive Guide To Django" (available on http://www.djangobook.com/).
Hope this helps!

Faster Development Rails or Django?

I have around 2 Weeks of Real development time to churn out a contact database system to replace various spreadsheets and pieces of paper laying around.
Also I need to develop two websites (with dynamic content) and a small AJAXian web service.
I have no experience of rails or django, but I can learn fast.
Both claim to be all about the fast development.
What is it that rails has that django doesn't have and vice versa that would accelerate the development of this application?
Also the contact database benifit more from the admin panel (dj) or the scaffolding of views (ror)?
(there will be a lot of CRUD operations)
The Django admin will generate a CRUD application that you can customize to suit almost any need, from your model definitions. I've used the admin for the main user interface for several projects and can tell you that it is a real timesaver. You don't have to spend any time whatsoever at writing templates or Javascript.
Django also has generic views which can do object detail, list views, update or delete on any model without you worrying about the logic of the app. You just supply the templates, hook into the urls and you're basically done.
For deployment I'd say Django and Rails are now equal. Rails has been painful to deploy, but things have changed greatly.
For a simple contact database the admin might be the biggest difference between Rails and Django. And the fact that you can run your Django project locally, with a real webserver without any configuration ('python manage.py runserver').
unless you are exactly equally experienced on both, you should definately use the one you are most comfortable in. If you don't know any python and you don't know any ruby, then you probably shouldn't use either. If you know PHP, you can get similar results with CakePHP or CodeIgniter. If you another language, you can ask about a Rails like MVC framework for that language on this website
Without experience in either one, with only two weeks to deliver a product, I would choose neither. If you have limited time, you need to leverage what you already know. It would take you two weeks just to get comfortable in either environment. Rails and Django are both popular and make it easy to accomplish a lot with a little time because of the number of details that are done for you in the background, without you having to think about it. If you don't know what those details are, you're not going to be able to leverage the power of either platform, and you're going to end up with a codebase that is a tangled mess of code that you don't need and is going to impact maintainability.
I do take issue #knutin's comment about the ease of deployment with Rails. That might have been true a few years ago, but today a Rails app is pretty easy to deploy even on a naked server, and if you plan on deploying on heroku its even easier. As far as I know there isn't a platform for django apps that offers anything like the scalability or ease of deployment that heroku and rails offers.
if you're dead set on doing one or the other, I'd recommend rails with the use of formtastic for generating your CRUD forms. Formtastic offers far more flexibility than the built-in Rails scaffold generators do, so you can go back and make things better while still using them.
Lastly, if you're determined to use something despite a learning curve, I've heard a lot of good things about hobo though I haven't yet used it on a project. You may find it easier to get started with than straight-up Rails.
This article has a good comparison, involving two developers without previous experience with either framework: https://docs.google.com/View?docid=dcn8282p_1hg4sr9
This is a question I still am trying to find the answer too, here is what i can tell you so far.
Preface
When it comes to scripting langauges I always prefer python, not only I feel more strong using python, but also the libraries are better and work faster. Also (and ruby devs will have something to say) I find Python a more understandable and readable code that Ruby.
Said this, Rails is an excellent framework! It has a lot more "magic" that Django, and now with Rails 3 you can write your ajax in unobtrusive Javascript which makes it beautiful to read. Also the path and form features are far better that Django's.
The big problem is this: As I said Rails does a lot for you (aka magic), the only problems is that if you want to escape those conventions for some reason you find yourself dealing with lots of problems, while with Django you have more control over your application.
Django also has the super-hardcore Admin and User application, no need to install any plugin, this is ALL done for you! Setting up users is incredibly easy and the Admin backend gives you CRUD for every model.
Overall I prefer Django, I understand it better and it does what I say, although I must say that, as far as things are going nowadays, Rails will have more support in the future.
Feel free to ask any question!! Hope it helped
Dan

How complicate can a Django application go?

I'm tasked to create a simple CRUD MVC application, and I thought it's a good opportunity to learn python. Because of its great documentation, I'm thinking now that I'll go with Django.
Now, this simple CRUD MVC application could become quite complicated in the future. I might have receive and issue JMS messages, display charts that are updated periodically (I'm thinking about ajax) and what not.
Given this I'm a little worried, since while I'm told it's easy to call Java code from python (I'm a Java developer), I'm also told that Django is generally best for content based web application, and can be restrictive.
Do you think it is okay to go with Django in this case?
simple CRUD MVC application
Django does this "out of the box" The admin interface is a simple, CRUD, MVC application. You don't do much programming to make this happen. You create the model. That's it. Use the Django admin for your CRUD application. Done.
I might have receive and issue JMS messages, display charts that are updated periodically (I'm thinking about ajax) and what not.
That's the point. Since you didn't waste time writing the CRUD application, you are able to write the other, more interesting stuff.
Look at http://hjb.python-hosting.com/ for a Python-JMS bridge.
We have FLEX front-end and Django-based RESTful web services. The Django apps create PDF's, and other things. The FLEX does pretty pictures and charts.
Django is generally best for content based web application, and can be restrictive.
Doesn't mean anything. Provide a quote or a link to whatever it is you're talking about.
Mozilla is currently rewriting two of our largest sites on Django. These are both fairly complex applications that interact with numerous online and offline services. With Python's large collection of libraries, anything Django doesn't do itself we've usually been able to find, or create pretty easily. For example, we have both cron jobs and on-demand offline tasks, backed by AMQP, which is similar to JMS.
Short answer: you can get pretty darn complicated if that's what you need to do, and odds are there's already a Python project or library to do what you need.

Categories

Resources