Sharing of various Django setup guides [closed] - python

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
This may be a little clean and green, however when I try to explain my setup to a rubber duck, many times I awake to find myself in a pile of my own hair and the duck still there, staring at me emotionlessly. thats when I knew it was time to escalate the matter to SO.
What frustrated me was, initially when I follow a guide that I think looks credible, install virtualenv etc etc, and following which, started my hello world project. And while researching on a webserver I was faced with the apache2 vs gunicorn dilema, I figured ok lets use gunicorn. Didn't think too much and got started with another Hello World app, then I realised that I missed out version control and created another hello world project and I am here biting on my nails and eating my hair as I found that I may have likely messed up the file system folder structure and convention, and here I am creating my forth django hello world app.
Someone save me from bootstrap hell.
OS: ubuntu 12.04 server lts
db: MySQl
Framework: Django
Background: To create a reporting app with utilises d3.js
facts: This project will not use PaaS
how I went about doing it,
installed easyinstall
installed pip
installed django ( pip install gunicorn django )
installed gunicorn
setup nginx
started django project (cmd: startproject, runproject)
----- here is the part where things get fuzzy -----
installing git???
installing django-south?
adding h5bp (to-do)
Would appreciate to know if I am doing this in the right order OR any other clear guides for setting up django

This is a difficult question to answer because its more about opinions than anything else; and everyone works a different way. However, if you understand the reason behind the recommendations, then you will be better prepared to judge other bootstrapping scripts and - even better - build your own that does what you want.
Here are things you need to ensure are taken care of.
Isolate your development packages from your system-wide Python install. Use virtual environments to accomplish this. Further, you should make sure you pin your packages so that you don't get surprises when versions are upgraded.
Use any form of version control. It doesn't have to be git. You don't need to use github.com. Use mercurial, cvs, bazaar or whatever else. The important part is you use something. So find out what works for you and get going.
For development, do not even bother with a web server. Django comes with a webserver that you should use during development. Run it with python manage.py runserver. When you are finished with your development, you should deploy any web server that supports wsgi. The documentation provides deployment guides that can help you with this.
Everyone and their dog has a recommendation for folder layout and structure. The problem is, each have their own reasons for recommending it. If you do not understand why you will only get frustrated with the layout. So, my suggestion is start with the standard layout that comes with django. The only thing I would add is that you create a docs/ directory where you stick any/all documentation for your project; and a requirements/ directory where you save all your requirements files and keep both of those updated.
Finally, some of my suggestions.
Use postgresql unless you have a compelling reason to go with mysql. postgresql works best with django and some ORM features (like using distinct on columns) only work with postgresql.
Keep your templates and views simple. Instead of cramming a lot of logic in the views, create other python modules that you can import. This will make your project easy to extend (for example, if you want to create an API). Your templates should have absolutely the minimal amount of logic. If you use custom template tags, make them as simple as possible because they are difficult to debug.
Don't be afraid of creating custom model managers and other tricks in the ORM. There is a lot of stuff you can do there that will make your application easier to develop.
django-south is recommended, but make sure you understand how it impacts your projects before you install it; otherwise you'll just end up after a few iterations with a migration that won't run - then you'll either spend a good amount of your time trying to fix the migrations, or simply dropping the database and starting over.

Found this great resource which was almost exactly what I am looking for.
epicserv updated 2013
https://gist.github.com/epicserve/1332256 (updated 2013)
senko updated 2011
http://senko.net/en/django-nginx-gunicorn/

Related

Recs on getting started with Django on Heroku, with Pycharm

I've been trying for a couple of days to get my first Django app up on Heroku, mainly following Heroku's instructions (https://devcenter.heroku.com/articles/getting-started-with-django — 
(The background: for those interested, I'm a Django newbie who's created his first app and I thought I'd put it online to show it off as part of my portfolio. Not so easy! My shared-hosting web host said: nothing doing. So I looked through various things and came on Heroku, which is a bit pricey for me to use as a web host, but at least I could practice deployment.)
But I'm having a great deal of trouble. I deinstalled my regular pythons and installed homebrew and all that, finally got Pycharm to play nicely with my Homebrew python, but can't get gunicorn to work within Pycharm, can't get foreman to work as it can't find gunicorn (although gunicorn is installed into Pycharm's virtual env), etc.
I know both that I don't have a lot of idea what I'm doing (I'm still trying to grok Django) and that it would be difficult for anyone to troubleshoot my situation. I'm curious to know if anyone can suggest a step-by-step — taking the Heroku link as a starting point up until where it says to run foreman — that I could follow to proceed. A link would be super-helpful. I'm a good programmer, but really haven't tackled all these setup intricacies before, or deal with WSGI issues or anything like that).
Thanks, I know it's a bit vague, but I'm a bit blinded by the light at the moment.
This may not be quite the answer you're looking for, but if you come over and give us a try at PythonAnyhwere.com, we specialise in Python hosting, we provide lots of instructions on how to get going with django, and are very happy to help you if you run into any problems....

Simplifying development process for Django

I'm a freelance editor and tutor as well as a fiction writer and artist looking to transition to the latter on a full-time basis. Naturally, part of that transition involves constructing a website; a dynamic site to which new content in various forms can be added with ease. Now, I've always intended to learn how to program, and I simply haven't the money to hire someone else to do it. So, having had a good experience with my brief dabblings in Python, I decided I'd go with Django for building my site.
I set up a Fedora Virtualbox for a development environment (as I didn't want to jump through hoops to make Windows work) and went to town on some Django tutorials. Everything went swimmingly until life intervened and I didn't touch the project for three weeks. I'm in a position to return to it now, but I've realized two things in the process. First, I'm having to do a fair bit of retracing of my steps just to find where certain files are, and second, I don't know how I'd go about deploying the site after I'm done building it. My intention is to get the cheapest Linode and host off that until some theoretical point in the future where I required more.
I suspect that re: the file organization issue, that's just something I'll become more familiar with over time, though if there are any tricks I should be aware of to simplify the structure of my overall Django development space, I'm eager to know them. However, what about deployment? How viable is it to, with sufficient knowledge, automate the process of pushing the whole file structure of a site with Git? And how can I do that in such a way that it doesn't tamper with the settings of my development environment?
As a Django developer i can assure you that it grows on you and becomes easier to understand the development environment.
You should remember that settings.py is probably going to be where your thoughts will be for quite a while in the start; the good part is that its only once, after you got it up and running you'll only touch settings.py to add new modules or change some configuration but its unlikely.
I believe there are hosts that integrate with git so that should not be a problem since you will probably just git clone your project's url into the host (and not forget to enable/configure wsgi)
To leave the settings.py out of the mess, you will tell git not to track the file with: git rm file; and then when you add your files for commit you do it with git add -u so it refers only to your tracked files.
I'm not sure if i was clear enough. (probably not) But, i hope i could help you in some way.

Continuous integration/Testing Python on Heroku

So I've been looking into ways to using Heroku for a small-scale personal project (Python Flask + MongoDB), however I can't seem to find much information on how to do simple continuos integration testing or simple unit testing on a Heroku staging instance. I feel that this would be necessary to make sure that everything will work in production, before actually making it public.
There doesn't seem to be much information on as to how I could achieve this. There are a couple of CI addons that would help, but they currently work only with Ruby/RoR (tddium, Rails on Fire) and proper testing on Heroku seems like a problem that should already be solved by a number of people. Buildpacks seem like a potential way to achieve what I need, but I'd rather use existing tools than re-invent the wheel myself.
So the question is, what are my options?
I wouldn't advise on running your tests on Heroku, as the platform isn't designed to do this. It will probably take you much longer to get the Platform to work than simply using another hosted service. There are lots of other alternatives (e.g. Codeship where I am one of the founders).
At Codeship we are currently working on Python support which will be released soon. MongoDB (as well as lots of other tools) is integrated nicely and works out of the box. We are also focusing very strongly on helping you deploy often and integrate that nicely, so you can work on your app and not your infrastructure.
CircleCi has Python support! It also directly supports MongoDB. You'll be able to set it up very easily.
None of the hosted CI solutions, Circle included, run directly on Heroku. We (Circle - I'm a founder) have looked into it, but the way people write tests make this awkward (they're really designed to be run on the same machine). Heroku is also very slow and memory constrained, while the main goal of a CI system is to get results to you quickly.

Whats the recipe for a safe enviroment to create/play with my web applications.

How can i create a safe environment to create new and play with my web applications?
My ingredients so far: python,flask,github,heroku --- I have effectively created a app using flask and heroku (it just says hello world)
I have some knowledge of python. Have read through but hardly understand the flaskr tutorial for Flask. I do however envision that i'm going to be very frustrated if i can't have some kind of version history of my stumblings.
Without being sure i feel like the recipe might include: Github and virtualenv and some coping pasting of directories...
whats a recommended way to do this?
Just setup a GitHub repository and start hacking away with Flask.
Some pointers:
Use SQLAlchemy for database operations. It's secure and easy to use.
Either dive right into your project or make some simple test ones with Flask. It's a really beautiful framework to work with and is easy to learn, so just try to accomplish some simple tasks and get used to how it works.
I suggest you to use virtualenv and virtualenvwrapper, this way you can work on isolated pythons without filling your system's python with many eggs and switch between them easily.

How to install (run) Jumo (Python/Django) on localhost

I am trying to run Jumo open source platform ( https://github.com/jumoconnect/openjumo) on my local machine (Windows 7). I have Python and Django installed and it works - I can create new project without problems, but I am not sure how to set existing project and make it work.
I am not experienced with Python/Django, so first I need to know whether it is hard task or not. I guess it's much complicated then installing WordPress or Joomla, but does that require a lot of work in order to set it up?
Can someone write some kind of guide if it is not too complicated? Or if there is some tutorial that explains how to do that, that would be great.
Just to be clear, I am not trying to learn something in one day, just want to see if this first step in using this platform is too hard, and if it's not, I'd continue learning, because this is exactly what I need for one project.
I use Python 2.7 and Django 1.3.1
Thanks
This project has a lot of external requirements which are not listed anywhere and unless you are comfortable and familiar with django, I wouldn't recommend installing it. Here are some but not all of the requirements that you'll need running:
Celery and django-celery
RabbitMQ (a broker for Celery), or another broker but then you'll have to edit settings.py again.
memcached (this is optional, as you can use django's own session middleware for development), but if you simply download the code and try to run it, you'll run into an error since the default settings.py has the default middleware commented out.
grappelli
django-jenkins (not required, but again, unless you edit the default settings.py, you'll get errors).
django-tastypie
django-debug-toolbar
Data science toolkit server
as you may know Django is a powerful web framework and Python is a programming language, for python itself you need more than a few months to become some kind of expert.
it's very easy to start, but not that easy to learn the whole stuff. Django is one of the most or maybe the most powerful web frameworks (beside Ruby on Rails).
my advice to you:
learn python's basics (there's many books such as dive into python,
...)
learn Django basics (Django Book)
use Django on a Gnu/Linux (for example Ubuntu)
learning basics of Django can be done in a few weeks.
consider deploying a Django website is not that easy. you need to know a little about Apache web server.
www.djangoproject.com
note that in python (like other programming languages) you need to define working path. errors mentioned in question's comments usually caused by this.
also you should check Python installation path. sometimes these kinds of errors occurs when there is a project with the same name as yours in python installation path.

Categories

Resources