具有多个应用程序的Django打包项目 [英] Django packaging project with multiple apps

查看:196
本文介绍了具有多个应用程序的Django打包项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打包我的Django项目,但没有成功.我的项目如下:

I'm trying to package my Django project without success. My project looks like this:

dsbg/
  manage.py

  dsbg/
    __init__.py
    urls.py
    wsgi.py

  app1/
    __init__.py
    models.py
    views.py
    urls.py

  app2/
    __init__.py
    models.py
    views.py
    urls.py

  settings/
    base.py
    local.py
    prod.py

  static/
        app1/
            images/
                background.gif
            style.css

  templates/
        home.html
        app1/
            detail.html
            index.html
        app2/
            detail.html
            index.html

我遵循了此处但我不确定自己做的是否正确(他们的示例只有一个应用:民意测验).我做了以下事情:

I followed the procedure here but I'm not sure I'm doing the right things (their example has only one app: polls). I did the following:

  • 在新目录django-dsbg中移动应用程序+静态+模板目录(将dsbg和设置保留在根目录中)
  • 在django-dsbg中,创建setup.py文件,指定软件包文件(app1和app2),并创建MANIFEST.in以包含静态目录和模板目录.
  • 在django-dsbg中,运行:

  • move apps + static + templates directories in new directory django-dsbg (keeping dsbg and settings in root)
  • in django-dsbg, create setup.py file, specifying packages files (app1 and app2) and create MANIFEST.in to include static and templates directories.
  • in django-dsbg, run:

 python setup.py sdist

  • 在django-dsbg的父目录中,运行:

  • in the parent directory of django-dsbg, run:

     pip install --user django-dsbg/dist/django-dsbg-0.1.tar.gz
    

  • 之后,该项目如下所示:

    After that, the project looks like this:

    dsbg/
      manage.py
    
      settings/
        base.py
        local.py
        prod.py
    
      dsbg/
        __init__.py
        urls.py
        wsgi.py
    
      django-dsbg/
        LICENSE
        MANIFEST.in
        README.rst
        app1/
           models.py
           views.py
           urls.py
        app2/
           models.py
           views.py
           urls.py
        templates/
           home.html
           app1/
             ...
           app2/
             ...
        static/
           ...
    

    现在在根目录(顶级dsbg)中,我尝试启动服务器:

    Now at the root directory (the top dsbg), I try to start the server:

    python manage.py runserver --settings=settings.local
    

    服务器运行良好,但是在指向本地主机时,浏览器显示:

    The server is starting well but when pointing at localhost, the browser says:

    TemplateDoesNotExist at / home.html. 
    ...
    Python Path: ['/home/patrick/django/dsbg/dsbg',
                  ...
                  '/home/patrick/.local/lib/python2.7/site-packages']
    

    此home.html文件位于django-dsbg/templates中. dsbg/dsbg和.local/lib/python2.7/site-packages目录都不包含home.html.后者包含我的所有应用,但不包含static或templates目录.

    This home.html file is located in django-dsbg/templates. Neither dsbg/dsbg nor .local/lib/python2.7/site-packages directories contain home.html. The latter contains all my apps but not the static or the templates directory.

    我做错了什么?有人能帮我吗? 任何帮助是极大的赞赏. 帕特里克

    What am I doing wrong? Can someone help me? Any help is greatly appreciated. Patrick

    推荐答案

    您需要模板的绝对路径,无论应用程序位于何处,您始终可以

    You need the absolute path to templates, doesn't matter where the apps are located, you could always just

    TEMPLATES_DIRS = ('/home/user/dsbg/django-dsbg/templates', )
    

    # Django 1.8 +
    Dirs = ['templates']
    

    这篇关于具有多个应用程序的Django打包项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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