<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sealyu

    --- 博客已遷移至: http://www.sealyu.com/blog

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

    In today’s world, web development is all about turnaround. Businesses want to maximize production outcome while minimizing development and production time. Small, lean development teams are increasingly becoming the normal large development departments. Enter Django: a popular Python web framework that invokes the RWAD (rapid web application development) and DRY (don’t repeat yourself) principles with clean, pragmatic design.

    This article is not about teaching you how to program in Python, nor how to use the Django framework. It’s about showing how to promote your Django applications onto an existing Apache or Lighttpd environment.

    We will conclude with a simple way that you can improve the performance of your Django application by using caching to speed up access time. This article also assumes that you are running Fedora as your web application server, but all the packages mentioned in this article are also available under the Extra Packages for Enterprise Linux repository , which means these instructions should also be valid under Red Hat Enterprise Linux or CentOS servers.

    What you need

    You must have Django installed:

    # yum install Django

    If you want to serve Django apps under Apache:

    # yum install httpd
    # yum install mod_python

    If you want to serve Django apps under Lighttpd:

    # yum install lighttpd
    # yum install lighttpd-fastcgi
    # yum install python-flup

    Installing memcached to ’speed up’ Django apps:

    # yum install memcached
    # yum install python-memcached

    Starting a new Django project

    1. Create a development workspace.

    $ mkdir -p $LOCATION_TO_YOUR_DEV_AREA
    $ cd $LOCATION_TO_YOUR_DEV_AREA

    2. Start a new base Django project. This creates the boiler plate project structure.

    $ django-admin.py startproject my_app

    3. Start the Django development web server on port 8080 (or whatever other port you’d like).

    Note: The development web server is just for testing and verification. Do not use it as a production application server!

    $ python manage.py runserver 8080

    4. Run your Django project under Apache with mod_python by enabling mod_python on httpd.conf (/etc/httpd/conf/httpd.conf).

    After installing mod_python, a file called python.conf should already be placed in /etc/httpd/conf.d/, which enables mod_python on your system.

    5. Create virtual hosts by creating a new file at /etc/httpd/conf.d/myapp.conf.

     

    DocumentRoot /var/www/html/
    ServerName your_domain_name
    ErrorLog logs/my_app-error.log
    CustomLog logs/my_app-access_log common


    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE my_app.settings
    PythonDebug On
    PythonPath “[’/var/www/django/’] + sys.path”


    Running your Django project under Lighthttpd with fastcgi

    The first thing you must do is start up your FastCGI server.

    ./manage.py runfcgi method=prefork socket=/var/www/myapp.sock pidfile=django_myapp.pid

    Then modify your lighttpd.conf file to use the FastCGI server.

    server.document-root = "/var/www/django/"
    fastcgi.server = (
    "/my_app.fcgi" => (
    "main" => (
    # Use host / port instead of socket for TCP fastcgi
    # "host" => "127.0.0.1",
    # "port" => 3033,
    "socket" => "/var/www/my_app.sock",
    "check-local" => "disable",
    )
    ),
    )
    alias.url = (
    "/media/" => "/var/www/django/media/",
    )

    url.rewrite-once = (
    "^(/media.*)$" => "$1",
    "^/favicon.ico$" => "/media/favicon.ico",
    "^(/.*)$" => "/my_app.fcgi$1",
    )

    Setting up caching in Django

    Django has many different caching backends, including database, memory, filesystem, and the ever popular memcached. According to http://www.danga.com/memcached/, memcached is “a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.” It’s used by high traffic sites such as Slashdot and Wikipedia. This makes it a prime candidate for caching in your cool new web app.

    First, verify that memcached is running using the memcached’s init script.

    $ /etc/init.d/memcached status
    memcached (pid 6771) is running...

    If it’s not running, you can manually start it.

    $ /sbin/service memcached start

    If you want to make sure it will automatically start every time after a reboot:

    $ /sbin/chkconfig --level 35 memcached on 

    Now that you have verified that memcached is running, you will want to tell your Django application to use memcached as it’s caching backend. You can do this by adding a CACHE_BACKEND entry to your settings.py file.

    CACHE_BACKEND = 'memcached://127.0.0.1:11211/'

    The format is “backend://host:port/” or “backend:///path” depending on the backend chosen. Since we are using memcached, we have the option to run multiple daemons on different servers and share the cache across multiple machines. If you want to do this all you must do is add in the servers:port combinations in the CACHE_BACKEND and separate them by semicolons. In this example we share the cache across three different memcached servers:

    CACHE_BACKEND = 'memcached://127.0.0.1:11211;192.168.0.10:11211;192.168.0.11/'

    For more information on the different types of caching that can be performed in the Django framework, please refer to their official documentation.

    posted on 2008-11-06 22:36 seal 閱讀(904) 評論(0)  編輯  收藏 所屬分類: Python
    主站蜘蛛池模板: 无码毛片一区二区三区视频免费播放 | 无码视频免费一区二三区| 国产成人亚洲精品91专区手机| 亚洲国产精品成人午夜在线观看| 久久精品国产亚洲Aⅴ蜜臀色欲| 羞羞网站在线免费观看| 国产成人久久AV免费| 国产国拍亚洲精品mv在线观看 | 国产日韩精品无码区免费专区国产| 免费无遮挡无码视频网站| 亚洲爆乳成av人在线视菜奈实| 国产精品va无码免费麻豆| 国内精品久久久久久久亚洲| 亚洲综合另类小说色区| 久久夜色精品国产噜噜噜亚洲AV| 亚洲区日韩精品中文字幕| 四虎成人免费大片在线| 99久久99久久精品免费看蜜桃 | 1000部拍拍拍18勿入免费视频软件| 亚洲精品~无码抽插| 国产精品免费视频一区| 免费的全黄一级录像带| 亚洲丶国产丶欧美一区二区三区| 亚洲一区二区三区四区在线观看| 无码专区一va亚洲v专区在线| 大学生一级毛片免费看| 国产婷婷成人久久Av免费高清| 免费大片av手机看片| 亚洲妇女无套内射精| 亚洲色偷精品一区二区三区| 亚洲小说区图片区| 内射干少妇亚洲69XXX| 亚洲最大AV网站在线观看| 亚洲精品成人a在线观看| 又黄又爽无遮挡免费视频| 成人免费看片又大又黄| 99热在线精品免费全部my| 在线免费观看亚洲| 亚洲一区二区三区免费观看| 日韩电影免费在线观看网站| 美女露隐私全部免费直播|