mirror of
https://github.com/wrabit/django-cotton.git
synced 2025-08-27 18:14:12 +00:00
Merge pull request #234 from fbinz/base_dir
Don't rely on existence of BASE_DIR settings variable.
This commit is contained in:
commit
b3ee2c68d2
4 changed files with 28 additions and 5 deletions
|
@ -474,6 +474,10 @@ In addition, Cotton enables you to navigate around some of the limitations with
|
|||
|
||||
The directory where your components are stored.
|
||||
|
||||
`COTTON_BASE_DIR` (default: None)
|
||||
|
||||
The directory that contains your project-level "templates" directory.
|
||||
|
||||
`COTTON_SNAKE_CASED_NAMES` (default: True)
|
||||
|
||||
Whether to search for component filenames in snake_case. If set to False, you can use kebab-cased / hyphenated filenames.
|
||||
|
|
|
@ -61,9 +61,14 @@ class Loader(BaseLoader):
|
|||
dirs.append(template_dir)
|
||||
|
||||
# Check project root templates, e.g. project/templates
|
||||
root_template_dir = os.path.join(settings.BASE_DIR, "templates")
|
||||
if os.path.isdir(root_template_dir):
|
||||
dirs.append(root_template_dir)
|
||||
base_dir = getattr(settings, "COTTON_BASE_DIR", None)
|
||||
if base_dir is None:
|
||||
base_dir = getattr(settings, "BASE_DIR", None)
|
||||
|
||||
if base_dir is not None:
|
||||
root_template_dir = os.path.join(base_dir, "templates")
|
||||
if os.path.isdir(root_template_dir):
|
||||
dirs.append(root_template_dir)
|
||||
|
||||
return dirs
|
||||
|
||||
|
|
|
@ -13,6 +13,17 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-6">
|
||||
<div>
|
||||
<code>COTTON_BASE_DIR</code>
|
||||
<div>str (default: None)</div>
|
||||
</div>
|
||||
<div>
|
||||
The base directory where - in addition to the app folders - cotton will search for the "templates" directory (see above).
|
||||
If not set, the `BASE_DIR` generated by `django-admin startproject` is used as a fallback, if it exists.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<c-hr />
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-6">
|
||||
|
@ -42,4 +53,4 @@
|
|||
</div>
|
||||
|
||||
|
||||
</c-layouts.with-sidebar>
|
||||
</c-layouts.with-sidebar>
|
||||
|
|
|
@ -81,7 +81,10 @@ TEMPLATES = [
|
|||
|
||||
<c-ul>
|
||||
<li><strong>App level</strong> - You can place your cotton folder in any of your installed app folders, like: <div><code>[project]/[app]/templates/cotton/row.html</code></div></li>
|
||||
<li><strong>Project root</strong> - You can place your cotton folder in a project level templates directory, like: <div><code>[project]/templates/cotton/row.html</code></div></li>
|
||||
<li>
|
||||
<strong>Project root</strong> - You can place your cotton folder in a project level templates directory, like: <div><code>[project]/templates/cotton/row.html</code></div>
|
||||
(where the <code>[project]</code> depends on the `BASE_DIR` or `COTTON_BASE_DIR` settings)
|
||||
</li>
|
||||
</c-ul>
|
||||
|
||||
<p>Any style will allow you to include your component the same way: <code>{{ '<c-row />'|force_escape }}</code></p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue