I'm trying to reach some of my css files but I can't seem to get the directory right.
For example I have a link in my home.html:
<link href="assets/plugins/revo-slider/css/settings.css" rel="stylesheet" type="text/css"/>
I've converted it to:
<link href="{% 'assets/plugins/revo-slider/css/settings.css' %}" rel="stylesheet" type="text/css"/>
But that's the incorrect directory because I recently moved the file to where it is now as shown below.
my folder structure is as follows:
project/
├────── Index/
│ ├──_static/
│ │ ├── css/ (.css files)
│ │ ├── js/ (javascript files)
│ │ ├── img/ (images files)
│ │ ├── media/ (video files)
│ │ └── plugins/ (.css plugin files)
│ │
│ └── templates/
│ └── index/
│ ├── home.html
│ └── about.html
├── manage.py
└── project folder with settings.py,url.py
my settings.py includes:
line 5: BASE_DIR = Path(__file__).resolve().parent.parent
line 90: STATICFILES_DIRS = [
"/index/static",
]
I've checked the similar questions and youtube tutorials but I've seen some which suggested I add:
os.path.join(BASE_DIR, 'static')
in line 91 but i've seen conflicting codes through Youtube tutorials, first step is getting the directory right in my html though, if anyone can help it'd be great
First of all, don't specify your static files directory (in line 90 in your case). If you use the name static for your directories, Django automatically discovers them. You can get rid of that entire line. Just be sure to use static name for your directories always.
For some reason if you want to specify your static directories, just use the directory name, don't specify the path. i.e.:
STATICFILES_DIRS = [
"/index/static",
]
should be:
STATICFILES_DIRS = [
"static",
]
Secondly, you should always namespace your static file directories. For example, in the static directory of each app, first, create a directory with the same name as the app name and keep your static files in there. This will let you use different static files even with the same names without any conflicts. Here is my suggested structure.
.
├── manage.py
├── my_app
│ └── static
│ └── my_app
│ ├── css
│ │ └── style.css
│ └── js
│ └── script.js
├── project
│ └── settings.py
└── static
And in your templates, you can use static files like this:
<link rel="stylesheet" href="{% static 'my_app/css/style.css' %}">
In development, Django will automatically discover your static files. And before pushing the project live in production, run python manage.py collectstatic and your static assets will be copied to the static directory in the project root. To make this work, you need to specify the static root path so Django will copy static assets from each app to the root static directory. Add this to your settings.py file:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
This is what I always do. I find this to be a cleaner way to manage static assets as each of your apps can have independent static files and by namespacing your static directories, you will be able to avoid conflicts.
Okay I've figured it out, I just removed the 'assets' tag from the directory link but can someone double check I have the correct code in my STATICFILES_DIRS please, I've seen conflicting answers I have the latest version of django
Related
I am trying to setup a template Jekyll project with the structure below. The goal is to reuse all markdown files in the project while being the least intrusive, keeping all custom layouts and configurations in a single folder.
.
├── README.md # some new project file stay in the roots
├── about.md # some new project file stay in the roots
├── docs # folder containing pages
│ └── assets
│ └── index.html # generated from README.md
│ └── about.html # generated from about.md
│ └── ...
├── jekyll # folder containing all jekyll specific files
│ └── _layout
│ └── assets
│ └── _config.yml
│ └── ...
To make this work, I'm running Jekyll from the /jekyll folder using the following configurations.
theme: jekyll-theme-cayman
source: ./..
destination: ./../docs
include:
- "./_layout"
- "./assets"
exclude:
- "./"
Here comes my problem: when I do this Jekyll ignores my custom layout. Could anyone help me understanding this problem?
P.S.: I'd prefer not to publish my custom layout as a new theme entirely.
I am trying to build a web application running wasm on the client side, and I am wondering what would be a good way of serving multiple pages.
My main concern is performance, because I would like to split the application up into contextual chunks instead of having one page with all of the content.
I am using Rust with the Yew framework for the client side, and so far I have only used yew_router to handle different routes on the client side, but they all work from the same HTML page and Wasm module. Now I would like to be able to serve different HTML pages with separate Wasm modules, and I am unsure how to realize this. Do I really have to write a dedicated crate for each page and compile those to individual Wasm modules, so I can serve them individually? Or is there some way I can compile one rust crate to multiple Wasm modules?
My current project structure looks like this:
.
├── Cargo.toml // workspace manifest
├── client
│ ├── Cargo.toml
│ ├── favicon.ico
│ ├── index.html
│ ├── main.js
│ ├── Makefile
│ ├── pkg // built using wasm-pack and rollup
│ │ ├── bundle.js
│ │ ├── client_bg.d.ts
│ │ ├── client_bg.wasm
│ │ ├── client.d.ts
│ │ ├── client.js
│ │ ├── package.json
│ │ └── snippets
│ ├── src
│ ├── statics
│ ├── styles
│ └── vendor
├── server
│ ├── Cargo.toml
│ └── src
└── ... other crates
and I run the server inside client/ where it responds with index.html to any incoming GET requests. The index.html links to the bundle.js in pkg/ which sets up the client_bg.wasm module.
Now I basically want to do this with another HTML page, with another Wasm module, preferably from the same Yew App in the client crate.
Thank you
Currently it's impossible to generate two wasm files from one crate. The solution is to use one create per wasm file and then let another build system to put output to correct places.
I'm trying to accomplish the task of linking to files within a collection from a post on a Jekyll site. However, I'm having an issue that relates to the collection having subdirectories, and those subdirectories having spaces in their names.
Here's a simplified example of how my site source is layed out:
├── 404.html
├── about.md
├── _config.yml
├── Gemfile
├── Gemfile.lock
├── index.md
├── _labs
│ └── Lab 01 Introduction
│ └── PS01 source.html
├── _posts
│ └── 2020-01-01-test_post.md
The post 2020-01-01-test_post.md contains the following markdown:
---
layout: post
title: "Introduction"
author: "Will Hopper"
---
[Link]({{ site.baseurl }}{% link _labs/Lab 01 Introduction/PS01 source.html %})
So far so good, and running jekyll serve succeeds just fine, meaning it can find the linked file at build time. The issue arises later, with the way jekyll has handled the spaces in the Lab 01 Introduction directory. Here is the contents of the _site folder after building:
└── _site
├── 404.html
├── about
│ └── index.html
├── assets
│ ├── main.css
│ └── minima-social-icons.svg
├── feed.xml
├── index.html
├── labs
│ └── Lab%2001%20Introduction
│ └── PS01 source.html
└── posts
└── test_post.html
As you can see, the spaces in the filename have been replaced with the URL encoded escapes, %20. As a result, the link in the post 404's.
I tried replacing the "raw" name of the folder with the URL encoded output, i.e., I tried {% link _labs/Lab%2001%20Introduction/PS01 source.html %} but now the site fails to build with Liquid Exception: Could not find document.
This HTML file is effectively a static file (i.e., it has no front matter). And curiously, Jekyll seems to leave spaces in the filenames alone!
Any ideas on what I could do to stop the spaces in my directory names from being URL encoded when the site is built?
I have a Jekyll blog and some of the raw posts have some additional files at the same level with the markdown file. For example:
.
├── _posts
├── first-post
├── 2007-10-29-first-post.md
└── download.zip
How can I and up with a generated structure such as
.
├── _sites
├── first-post
├── index.html
└── download.zip
The download.zip file needs to be in the same location as its dependent post (I cannot use any includes or other redirect tricks)
Try this jekyll-postfiles which is:
A Jekyll plugin that copies static files from the _posts to the _site folder
In my Dynamic Web Project, I have the following folder structure relative to the WebContent folder:
WebContent/
├── META-INF/
├── WEB-INF/
└── index.xhtml
So if I deploy my application to the server I can access it at the location: localhost:<port><context-root> which would display the index.xhtml file under the WebContent folder. I have other sections that I would like to put in their own folder. But simply for organizational reasons, it'd be nice to have all the static files, such as the XHTML files, in its own folder like:
WebContent/
├── META-INF/
├── WEB-INF/
└── Static/
├── Section/
│ └── index.xhtml
└── index.xhtml
But now if I point to localhost:<port><context-root> it won't open the index.xhtml file (because it's now located under the /Static folder). Is there a way to have localhost:<port><context-root> "point" to my Static directory without displaying it in the URL (without showing /Static)?
You can configure the <welcome-file-list> in your web.xml, where you can specify the file you want to visit as default page.