1. Briefly
I don't find, how I can to disable rendering some files with md and html extensions.
2. Detail
I use Pelican and write my articles use Markdown markup. For example, I want to create custom 404 page in GitHub Pages. I need to have 2 files in root directory of my site: 404.md and 404.html. I create these files in my content folder → I run pelican content command → I get output.
D:\Kristinita>pelican content
WARNING: Meta tag in file D:\Kristinita\content\404.html does not have a 'name' attribute, skipping. Attributes: http-equiv="X-UA-Compatible", content="IE=edge"
ERROR: Skipping .\404.md: could not find information about 'title'
3. Example of expected behavior
I set in pelicanconf.py:
NOT_RENDERING = ['404.md', '404.html']
I run pelican content → 404.md and 404.html files don't have modifications in output.
4. Did not help
I set in pelicanconf.py file:
STATIC_PATHS = ['']
Files with other extension, exclude md and html, copy to the output directory without modification, warnings and errors, but it no work for md and html files.
I use “hack” — I write extensions in UPPERCASE. For example, I create files 404.MD and 404.HTML files instead of 404.md and 404.html. But I don't get custom 404 page in GitHub Pages with UPPERCASE extensions.
I find OUTPUT_SOURCE setting in documentation → I set in pelicanconf.py:
OUTPUT_SOURCES = True
OUTPUT_SOURCES_EXTENSION = '.md'
I run pelican content command → I get error and warning in output, I don't get original 404.md in output. It don't solve my problem.
I would suggest moving those files into a separate directory within the content directory, e.g.:
content/
static/
404.html
404.md
Then you can configure Pelican to treat that directory as a static source:
STATIC_PATHS = [
'static',
]
and move the two files to the root of the output directory on processing:
EXTRA_PATH_METADATA = {
'static/404.html': {'path': '404.html'},
'static/404.md': {'path': '404.md'},
}
To make the processor ignore those files, per this GitHub issue, you will also need to set:
ARTICLE_EXCLUDES = [
'static'
]
Related
I'm new to Django. I created a web page with Django, now I'm having problems with statically loading files on templates. I don't understand what's the problem because if I put it in only just one folder it works but if I change the directory of that folder it gives me a 404 not found error. It looks something like this:
<img src="/media/{{cat.image_name}}" alt="#" height="350">
Here "media" is the folder where my image files are and "{{cat.image_name}}" is the name of that image which is passed through the database and this works.
However, if I write
<img src="/admin/public/media/{{cat.image_name}}" alt="#" height="350">
were admin>public>media is where I have placed my images.
I get this error:
Not Found: /admin/public/media/freelancer.jpg
[09/Dec/2019 18:23:30] "GET /admin/public/media/freelancer.jpg HTTP/1.1" 404 1852
Can anyone help me, please?
Django calls these files "staticfiles" and their path conventionally contains "static". These are files that you maintain in your source repository and are not in any way uploaded by users or admins: typically all JS, CSS and image assets for JS/CSS/HTML layout.
How to configure static files is well documented on https://docs.djangoproject.com/en/2.2/howto/static-files/.
Any files that are uploaded by the users/admins (dynamic content) are placed under a path conventionally named "media", as documented on https://docs.djangoproject.com/en/2.2/topics/files/, https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-MEDIA_ROOT.
In your case:
If /admin/public/media/ is a local file path it is not visible per default in your web server (which is good). File path != URL - which is why there is STATIC_ROOT (file path) and STATIC_URL (the url), and same with MEDIA_ROOT and MEDIA_URL. Django takes care that what you provide under the file path STATIC_ROOT is visible under STATIC_URL by default. If you want do not use this mechanism you have to implement it yourself:
copy the files from the file path /admin/public/media to a directory that is on your webserver and accessible by the web server
implement a URL route - either in Django or in your proxy (Nginx or Apache HTTP)
For larger applications, it is sensible to setup an Nginx or Apache Webserver to serve the static files from a directory in which Django has placed them when running ./manage.py collectstatic. These proxies serve static files much faster than Django, while the Django server has than more resources to server the dynamic (DB) content.
Django static files work with settings, if you do not add whatever path to your staticfiles dirs it will not work
I'm working to modify a cookiecutter Flask app. I'm working locally on WIN7 .
I've set up bower to install the front end dependencies under the static root by using a .bowerrc file in the document root containing:
{ "directory" : "myflaskapp/static/bower_components" }
This cookiecutter uses flask-assets to manage the project assets. Following https://adambard.com/blog/fresh-flask-setup/ I've modified myflaskapp/assets.py file :
from flask_assets import Bundle, Environment
import os
css = Bundle(
"libs/bootstrap/dist/css/spacelab/bootstrap.css",
"bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css",
"css/style.css",
"css/home.css",
filters="cssmin",
output="public/css/common.css"
)
js = Bundle(
"libs/jQuery/dist/jquery.js",
"libs/bootstrap/dist/js/bootstrap.js",
"bower_components/moment/moment.js",
"bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js",
"js/plugins.js",
filters='jsmin',
output="public/js/common.js"
)
assets = Environment()
assets.register("js_all", js)
assets.register("css_all", css)
The debug setting is set to false, meaning the assets should be compressed and minified.
Before I send a request:
After:
shouldn't the files go in static/public/css and static/public/js
This particular cookiecutter recipe has a public Blueprint that declares that its static files go into the static directory. I'm not sure why the author included empty static/public/{css,js} directories; they are probably just leftovers from an earlier stage of development and were neglected. I've removed the static/public directory in my instantiation of this recipe (well, a similar one with a similar problem) to no harm.
I am creating a static site with Pelican and I'm confused about how to add a favicon to it.
I've seen in the documentation that:
You can also use the EXTRA_PATH_METADATA mechanism to place a
favicon.ico or robots.txt at the root of any site.
I don't know where to put my favicon.ico file and what to specify in the EXTRA_PATH_METADATA setting (if this is really the setting that should be used).
In my pelicanconf.py, I have:
STATIC_PATHS = [
'images',
'extra', # this
]
EXTRA_PATH_METADATA = {
'extra/custom.css': {'path': 'custom.css'},
'extra/robots.txt': {'path': 'robots.txt'},
'extra/favicon.ico': {'path': 'favicon.ico'}, # and this
'extra/CNAME': {'path': 'CNAME'},
'extra/LICENSE': {'path': 'LICENSE'},
'extra/README': {'path': 'README'},
}
The structure for these extra files is then:
/content
/extra
favicon.ico
robots.txt
See the documentation, which shows a similar layout.
The official way #jonrsharpe described doesn't work for my page. I don't know why, it should.
I decided to put the favicon.ico in the image folder and to insert a link in base.html to get it work:
<link rel="shortcut icon" href="{{ SITEURL }}/images/favicon.ico?v=2" />
I used the technique outlined on the Pelican Wiki: https://github.com/getpelican/pelican/wiki/Tips-n-Tricks#copying-faviconrobotstxt
Repeating here in case that page disappears:
create a directory beside your content dir, and put all your favicon items there.
in your Makefile, add if test -d $(BASEDIR)/extra; then cp $(BASEDIR)/extra/* $(OUTPUTDIR)/; fi to any spots that build the site (ex publish, html, etc)
Now when you build the site, everything in extra/ will get copied to the root of /output.
I have simple Bottle application which serves a page for /Startpage location. The index.html page is located under /banana folder and the banana folder is located under the same folder where my views.py exist.
When I try this, its unable to find the page and throws internal server error
#app.wrap_app.route('/StartPage',method='GET')
def doStartPage():
return template('banana/index.html')
How can I refer my /banana folder in my template?
The bottle FAQ specifies the following
Bottle searches in ./ and ./views/ for templates. In a mod_python or mod_wsgi environment, the working directory (./) depends on your Apache settings. You should add an absolute path to the template search path so bottle searches the right paths.
You will need to add the bananas folder to the TEMPLATE_PATH
base_path = os.path.abspath(os.path.dirname(__file__))
bananas_path = os.path.join(base_path, 'bananas')
bottle.TEMPLATE_PATH.insert(0, bananas_path)
EDIT: Improved the answer with Graham's suggestion to use paths relative to where the code is located.
You can do something like this :
Create a rooting rule for your folder :
#route('/banana/<filepath:path>')
def file_stac(filepath):
return static_file(filepath, root="./banana")
And then, you only need to refer to this folder like this :
#route('/foo')
def bar():
return template('banana/foo.tpl')
You can do the same for as many folder as you want, and this is usefull for serving css/js files inside a template (on your template, you can then do :
<link href="banana/css/bootstrap.min.css" rel="stylesheet">
Hope it helped !
Almost 8 years late, but I did as follow for my issue, but replacing my folder with yours:
#route(/banana/<filename>)
def banana(filename):
return static_file(filename, root='./views/banana/')
How can I add a custom css file? The following config does not work:
# conf.py
html_static_path = ['_static']
html_theme = 'default'
html_theme_options = {
'cssfiles': ['_static/style.css']
}
Result:
$ make html
Running Sphinx v1.2.2
loading pickled environment... not yet created
building [html]: targets for 2 source files that are out of date
updating environment: 2 added, 0 changed, 0 removed
reading sources... [ 50%] help
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents...
Theme error:
unsupported theme option 'cssfiles' given
A simpler way is to add this to your conf.py:
def setup(app):
app.add_css_file('css/custom.css') # may also be an URL
Then put the file into the _static/css/ folder.
You should be able to include custom css by extending the default sphinx theme. In your conf.py you would specify where your extension to the theme would be, such as.
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Then in _templates you would create a extension to the default theme named 'layout.html' that would include your cssfiles such as.
{# layout.html #}
{# Import the layout of the theme. #}
{% extends "!layout.html" %}
{% set css_files = css_files + ['_static/style.css'] %}
See sphinx's documentation on templating for more information.
The options that you can configure via html_theme_options are theme-dependent. Check out the [options] section of your theme’s theme.conf to find out what is available.
On a global basis, though, you can define html_context in your conf.py to override the settings for css_files (and, for that matter, script_files too):
html_context = {
'css_files': ['_static/custom.css'],
}
(For reference, have a look at Sphinx’s builders.html.StandaloneHTMLBuilder.prepare_writing() and see how self.globalcontext gets populated there.)
I'm using Sphinx 3.2.
I was able to add some simple custom CSS by doing the following:
add this line in conf.py right under html_static_path = ['_static']:
html_css_files = ['css/custom.css']
go to docs/_static/ and add css/custom.css
add custom css to your file then $ make html
Source