在GoDaddy上安装django站点 [英] Installing a django site on GoDaddy

查看:1242
本文介绍了在GoDaddy上安装django站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前从未部署过Django网站。我目前正在寻找在我的豪华GoDaddy帐户中设置。有没有人有任何关于如何在GoDaddy上安装python和django的文档?

解决方案

为了将来参考,已经移动...



可以使用Django在GoDaddy托管,使用VirtualEnv,因为他们建议。 Python 2.7本机安装并且工作正常,但不是要运行的默认版本。




  • 在您的网站上启用SSH访问。

  • 使用主机面板设置您的初始MySQL数据库。它不需要任何条目,只需确保它存在并记下连接信息。

  • SSH,下载VirtualEnv.py。您可以获取整个tarball,但您只需要单个文件。

  • 运行'/usr/bin/python2.7 virtualenv.py --system-site-packages your_new_env'
  • 运行'source your_new_env / bin / activate'

  • 运行'pip install django'

  • django教程直接,除了当然不使用runserver(因为你已经有一个网络服务器运行)



这适用于我的豪华帐户,虽然我仍然建议任何人谁绝对想使用Django寻求替代主机。 GoDaddy不是很友好,我不确定一切都会继续工作。





编辑



我意识到如何让Django在Apache中正常运行,而没有常规的mod_ *选项,也可能会有一些混乱。这是我的方法:




  • 在html目录结构之外的某个地方创建django项目。例如在〜/ code中运行django-admin来创建〜/ code / yoursite

  • 按照Django教程中所述按照正常的项目和数据库设置。


  • 在您的虚拟python环境中运行'pip install flup'。

  • 在〜/ code()中创建以下脚本'django_cgi.py'路径!

     #!〜/ your_new_env / bin / python 
    import sys,os

    #为项目添加一个自定义Python路径
    sys.path.insert(0,/ must / be / full / path / to / code / yoursite)

    #设置DJANGO_SETTINGS_MODULE环境变量。
    #这应该匹配您添加到
    os.environ ['DJANGO_SETTINGS_MODULE'] ='yoursite.settings'

    以上路径的项目的名称,从django.core。 server.fastcgi import runfastcgi
    runfastcgi(method =threaded,daemonize =false)


  • 在〜/ html中,创建或编辑.htaccess文件,其中包含以下变体:

      RewriteEngine On 
    RewriteCond%{REQUEST_URI}!= / mysite.cgi
    RewriteRule ^(。*)$ /mysite.cgi [QSA,L,PT]
    pre>

  • 最后,创建〜/ html / mysite.cgi如下:

     #!/ bin / sh 
    〜/ your_new_env / bin / python〜/ code / django_cgi.py 2>& 1


  • 确保一切都正确地被修改(755)



简化但功能齐全,并应导致任何页面或文件的所有请求被传递到Django。



这种周期性的原因是GoDaddy只提供我们不能使用的旧版本的Python的本机CGI支持,所以我们必须使用我们的虚拟环境。虽然我们不能直接在CGI脚本中使用,但我们可以幸运的是运行一个shell脚本并手动调用它。 mod_rewrite规则只是确保所有流量都通过Django。



参考

Django with FastCGI

Django教程开始

VirtualEnv


I have never deployed a Django site before. I am currently looking to set it up in my deluxe GoDaddy account. Does anyone have any documentation on how to go about installing python and django on GoDaddy?

解决方案

For future reference, as I assume you have moved on...

It is possible to use Django on GoDaddy hosting, using VirtualEnv as they recommend. Python 2.7 is natively installed and works fine, though it isn't the default version to be run.

  • Enable SSH access on your site.
  • Use the hosting panel to setup your intial MySQL database. It doesn't need any entries, just make sure it exists and note down the connection info.
  • SSH in, download VirtualEnv.py. You may get the entire tarball, but you only need the single file.
  • Run '/usr/bin/python2.7 virtualenv.py --system-site-packages your_new_env'
  • Run 'source your_new_env/bin/activate'
  • Run 'pip install django'
  • You can now follow the django tutorials directly, except of course not using runserver (as you already have a webserver running)

This works for me on a deluxe account, though I would still recommend that anyone who definitely wants to use Django seek alternate hosting. GoDaddy is not very friendly, and I am not certain that everything will continue to work.


EDIT

I realized there may also be some confusion in how to get Django running normally inside Apache, without the regular mod_* options. This was my approach:

  • Create your django project somewhere outside of the html directory structure. For example run django-admin in ~/code to create ~/code/yoursite
  • Follow the normal project and database setup as described in the Django tutorials.
  • From your virtual python environment, run 'pip install flup'.
  • Create the following script 'django_cgi.py' inside ~/code (Note the python path!):

    #!~/your_new_env/bin/python
    import sys, os
    
    # Add a custom Python path for your project
    sys.path.insert(0, "/must/be/full/path/to/code/yoursite")
    
    # Set the DJANGO_SETTINGS_MODULE environment variable.
    # This should match the name for the project you added to the path above
    os.environ['DJANGO_SETTINGS_MODULE'] = 'yoursite.settings'
    
    from django.core.servers.fastcgi import runfastcgi
    runfastcgi(method="threaded", daemonize="false")
    

  • Inside ~/html, create or edit the .htaccess file with some variant of the following:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !=/mysite.cgi
    RewriteRule ^(.*)$ /mysite.cgi [QSA,L,PT]
    

  • Finally, create ~/html/mysite.cgi as follows:

    #!/bin/sh
    ~/your_new_env/bin/python ~/code/django_cgi.py 2>&1
    

  • Ensure everything is chmod'ed appropriately (755)

This is over simplified but functional, and should result in every request for any page or file being passed off to Django.

The reason for this runaround is that GoDaddy provides only native CGI support for old versions of Python we can't use, so we must use our virtual environment. While we cannot use that directly in the CGI scripts, we can fortunately run a shell script and invoke it manually. The mod_rewrite rule just ensures all traffic goes through Django.

References
Django with FastCGI
Start of Django Tutorials
VirtualEnv

这篇关于在GoDaddy上安装django站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆