Opened 7 years ago

Last modified 5 years ago

#5605 assigned Bug/Something is broken

install django for the use of MF/PL members

Reported by: https://id.mayfirst.org/dkg Owned by: https://id.mayfirst.org/dkg
Priority: Urgent Component: Tech
Keywords: django python viewsic.mayfirst.org Cc:
Sensitive: no

Description

As proposed in #5408, let's get some python going:

i want the django web framework available for MF/PL members. I'm going to install python-django on viewsic as a demonstration, so that i can verify how to hook it into our apache configs.

Change History (10)

comment:1 Changed 7 years ago by https://id.mayfirst.org/ross

  • Status changed from new to assigned

Ha! I was going to do this as well, though not on viewsic. In the django documentation, as well as media goblin http://mediagoblin.org/, It seems that the preferred method is to create python virtual environments. Obviously python-mysqldb is also a required package, though I'm not sure if PyMySQL is a better option http://pypi.python.org/pypi/PyMySQL/0.2 for virtual environments.

comment:2 Changed 7 years ago by https://id.mayfirst.org/dkg

yuck python-mysqldb :( This isn't a required package -- it's only needed if you want to run django against a mysql database. Other options include python-sqlite and python-psycopg2 (for postgres, if we ever get psql in place on moshes).

Could you link directly to the django documentation that says that the preferred method is virtual environments? the thought of maintaining some number of python virtualenvs per member makes our current painful gymnastics around drupal module maintenance seem like a walk in the park :)

On viewsic, i've gone ahead and installed:

I'm looking into the rest of the setup.

comment:3 Changed 7 years ago by https://id.mayfirst.org/dkg

I also had to install python-flup in order to get django working with fastcgi. I'm still testing, but i'll write up my mf/pl specific docs when i'm confident things are functional.

comment:4 Changed 6 years ago by https://id.mayfirst.org/dkg

I've just pushed 0f01da0/puppet, adding the relevant packages to the standard mosh profile.

Last edited 6 years ago by https://id.mayfirst.org/dkg (previous) (diff)

comment:5 Changed 6 years ago by https://id.mayfirst.org/dkg

  • Priority changed from Medium to Urgent

This just needs me to write up a bit of documentation.

comment:6 Changed 6 years ago by https://id.mayfirst.org/rocus

Hey folks, I'm trying to set up a simple django app on brown and wanted to throw a few comments.

When I develop in django, I really love virtualenv because it lets be separate my project from the hosting enviroment. I can fix the version of django and whatever other modules I use, plus I don't have to care about if some module is installed or not. If it's available with pip, then I can use it. Of course, this can't work with a shared django for mayfirst users.

However, as a system admin this means that I need to ensure that I keep everything up to date. However, I've noticed that django updates don't seem as urgent as drupal updates. Also, django apps usually have updates of their own, as opposed to just relying on 3rd party module updates like drupal apps typically do. This means that admins probably need to do their own updates in any case.

It seemed pretty easy to use virtualenv to create an environment and then install mysql-python and friends.

How did you get the fcgi part working? I tried to follow these directions, but it doesn't seem to be working for me: https://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#apache-shared-hosting. I get 400 bad request when I load my homepage.

So, for me, I wouldn't really care about a shared django setup. However, I would really love being able to easily connect a django app to apache. I'm thinking of a page that inputs the virtualenv root, the root of the django project, and it would create the fcgi wrapper and add the apache config to use it. One other nice option would be other directories to add to the python path.

comment:7 Changed 5 years ago by https://id.mayfirst.org/gripuqam

I connected Django apps to Apache using fcgid on chelsea. Do you still need some help?

comment:8 Changed 5 years ago by https://id.mayfirst.org/rocus

It's not super-urgent, but if you wanted to give me steps I would appreciate it.

comment:9 Changed 5 years ago by https://id.mayfirst.org/gripuqam

I see 3 main steps.

  1. Application desing. Only very light Django applications start fast enough to be useful with fcgid. Django database cache may help, but the time to wait for the first page may be an issue. I never tried https://www.djangopackages.com/packages/p/nano/ maybe it is fast enough. The result from some tests I did indicates that the Python Pyramid web framework starts faster than django and it has lot of possibilities http://docs.pylonsproject.org/en/latest/docs/pyramid.html . Flask seems to be easy, simple and popular, it may start fast enough for fcgid https://en.wikipedia.org/wiki/Flask_%28web_framework%29 . Python WSGI application seems to work far better then they stay permanently in RAM memory than with a short lived fcgid, this is a major issue for low traffic websites. On the PHP world, http://www.yiiframework.com/ is fast even on loaded machines and easy to use. It does not requires to stay in memory.
  2. Apache configuration. The Apache documentation for fcgid helps a lot, as well as Django's one. As suggested just before in the first point, WSGI applications tend to start slowly and serve following pages fast. Sometimes (@mayfirst) the fcgid configuration allows to start more than one fcgi process. In the case of WSGI application, my opinion is that it just overloads the CPU. So I would recommend to limit it to one. Somewhere in the documentation it is explained why you cannot put the fcgi file in the cgi folder, but you can put it in a subdirectory. One last point, Apache documentation suggest to avoid using .htaccess, but explains far better how to use them than the other configuration files. @mayfirst the red web interface allows to change the configuration file, and I wrote some code for it. The cool point is that it allows to completely hide the fcgi file name and directory.
  3. Python fcgi file. Django documentation explains how to connect Django to fcgi, there is a special way to do it and it will be supressed in future versions of Django. It is not a big issue, that code was not really needed, as flup makes it also. For debugging, a trivial WSGI application may be used, just to be sure that the Apache configuration is OK. The #! line can refer to python in a virtualenv, if needed, but python modules should as much as possible taken from debian. The fcgi file must be executable by the process of the website, as configured in the red web interface. To test it, start it in a shell as that precise unix user. Some html code should print in the shell window. This test also gives an estimate of the time needed to start the application. This is possible because with flup fcgi scripts are also cgi scripts.

I do not know if this is useful. I may add some code example?

comment:10 Changed 5 years ago by https://id.mayfirst.org/gripuqam

Apache configuration Limit to one or a little few fcgi process Member control panel web configuration settings Add the following line FcgidMaxProcessesPerClass 1

This can be tested with the command line top in a shell, while using the application in a web browser.

Last edited 5 years ago by https://id.mayfirst.org/gripuqam (previous) (diff)

Please login to add comments to this ticket.

Note: See TracTickets for help on using tickets.