喜欢的Django Tips&特征? [英] Favorite Django Tips & Features?

查看:120
本文介绍了喜欢的Django Tips&特征?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

受问题系列隐藏的...的功能的启发,我很好奇地听到您最喜欢的Django提示或不太了解但有用的功能。

Inspired by the question series 'Hidden features of ...', I am curious to hear about your favorite Django tips or lesser known but useful features you know of.


  • 请仅在每个答案中只提供一个提示。

  • 添加Django版本要求(如果有)

推荐答案

我只想从自己的提示开始:)

I'm just going to start with a tip from myself :)

在settings.py中使用os.path.dirname()来避免硬编码的目录。

请不要在你的settings.py中硬编码路径你想在不同的地方运行你的项目。如果您的模板和静态文件位于Django项目目录中,请在settings.py中使用以下代码:

Don't hardcode path's in your settings.py if you want to run your project in different locations. Use the following code in settings.py if your templates and static files are located within the Django project directory:

# settings.py
import os
PROJECT_DIR = os.path.dirname(__file__)
...
STATIC_DOC_ROOT = os.path.join(PROJECT_DIR, "static")
...
TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR, "templates"),
)

点数:我从屏幕截图 Django From the Ground Up '。

Credits: I got this tip from the screencast 'Django From the Ground Up'.

这篇关于喜欢的Django Tips&特征?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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