CSS file not loading for page with multiple arguments - python

I am working with google app engine for a class, and while working on a project, I came across something strange that I can't figure out. When I load a site with multiple arguments, such as www.something.com/something/1, the css file doesn't affect the page. It does this even if I copy and paste the exact code from another working html file. I am guessing it has to do with the multiple arguments and maybe me not defining something in the app.yaml file, but I am not sure really. Any help would be appreciated, let me know if you need any code, I didn't figure it would be useful in this case.
WWaldo
Edit:
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/>
<title>Google App Engine</title>
<link rel="stylesheet" type="text/css" href="stylesheets/page.css"/>
</head>

You're not showing any code so it's hard to tell for sure, but my guess is that you are using relative references to your CSS files:
<link rel="stylesheet" href="styles.css">
these will break when you're in a different directory. /something/1 will be interpreted by the browser as a different directory, so it will search for
/something/1/styles.css
the best solution is usually to use absolute paths:
<link rel="stylesheet" href="/stylesheets/styles.css">

Related

modify epub file by python's ebooklib, but all the contents inside <head> was lost

I'm using the python ebook library ebooklib to modify a batch of epub files. The dummy code is as the following.
book = epub.read_epub(input_path)
page_add = epub.EpubHtml(title='index_add', file_name='index_add.html', lang='en')
page_add.content = u'''
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<body>
<div>
I'm a new added page
</div>
</body>
</html>
'''
book.add_item(page_add)
book.spine.insert(1, page_add)
epub.write_epub(output_path, book, {})
After running the code, a new epub file was generated, and the new page was added to it. The issue is that all the original content of the original epub file lost their styles.
As we know, the epub file is composed of HTML files. I changed the file extension from .epub to .zip, and then unzip it, then I can get all the HTML files. After digging into these files for a while, I found the reason of losing all the style is that all the stylesheet file was located inside the <head> tag of all the original HTML files, but the new file lost all of these content inside the <head> tag. The original <head> looks like the following:
<head>
<link href="../stylesheet.css" rel="stylesheet" type="text/css"/>
<link href="../page_styles.css" rel="stylesheet" type="text/css"/>
</head>
From the ebooklib's doc, I found the following description:
When defining content you can define it as valid HTML file or just parts of HTML elements you have as a content. It will ignore whatever you have in <head> element.
I think this may be the reason why all the content inside <head> tag was lost. I don't know why ebooklib did this. Does anyone have a way to fix it? I think my requirement is quite common. Just add a page into lots of existed epub files.
Any help will be highly appreciated.
Author of Ebooklib here. The only proper way to do it with Ebooklib is to read EPUB file and construct new EPUB from scratch by cherry picking what you need from the original file. You were never supposed to read the file, modify it and write it down because we wanted to always end up with valid EPUB3 and our approach was "I will ignore all the garbage metadata, extra files, just take what I need and keep my layout of the folders".
That being said, that was for the online publishing system we worked on. Using Ebooklib outside of the system it does make a lot of sense to be able to do something like that. I am not sure at the moment how much changes that would require. Will take a look.
Aleksandar

cant load static file in django

I copied a HTML page with many images and javascript codes.
I created the static folder and did everything that is needed, and when I'm tying to load the source with static tag such as:
<link rel="stylesheet" type="text/css" href="{% static 'styles/bootstrap4/bootstrap.min.css' %}">
I'm still getting an error:
GET http://127.0.0.1:8000/static/styles/bootstrap4/bootstrap.min.css net::ERR_ABORTED 404 (Not Found)
All it did is to add static in the url and I dont understand why?
I cant find how to load jinja in pycharm so my tags are white.
Have you looked at the Django Documentation?
Serving the files
In addition to these configuration steps, you’ll also need to actually serve the static files.
During development, if you use django.contrib.staticfiles, this will be done automatically by runserver when DEBUG is set to True (see django.contrib.staticfiles.views.serve()).
This method is grossly inefficient and probably insecure, so it is unsuitable for production.
See Deploying static files for proper strategies to serve static files in production environments.

how to use Bootstrap theme in Django? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am new to Python programming and just started Django, I have a small task to use build a bootstrap blog. I have done some work with jinja templates in django. But i want to know how would i use bootstrap 3 in django because django templates work on jinja style like blocks statements and inheritance.
lot of confusion, any one here who have done this sort of work, kindly help.
also google it and found a lot of libraries, but the structure is confusing me, keep in mind that i am at beginner level.
You can download the static files and copy them in your project's static library, or you can use them via CDN, that is putting in your template's header links to the Bootstrap CDN:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
in django, you have static folder which contains css, js and image folders normally.
you put bootstrap css files into css folder, js files into js folder and fonts into images.
and you link to them in template this way:
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css">
or if you activated staticfiles app, then
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.css' %}">
the same goes for js files. just read django docs, it is the best docs ever!
I'll echo what the other answers have said, but for a succinct and easy to follow example see:
http://www.tangowithdjango.com/book/chapters/bootstrap.html
for a step by step instruction on how to bootstrap your django app.

Custom Fonts on Heroku with Django/Python

I'm using custom fonts from Pixeden, which are similar to FontAwesome. For some reason, the custom font-faces are not rendering, though I've placed all of the necessary files in my static folder. How do you get custom fonts working on Heroku with Python?
I'm using Django Storages, Django Pipeline, and Amazon S3.
I'll reply because I have had this problem lately and I resolved it. If you are using a font for example from googleapis in your html page, just remove http: at the beginning, so inside <head> instead of:
<link href="http://fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
use:
<link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
This is an old question, but it might benefit someone who stumbles upon it:
The issue here is that you cannot import the fonts with good old insecure http. It will work for your local enviroment, but not on Heroku.
You should use https instead!
Do it like this:
<link href="https://fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">

Plone: Using the default skin for administration

I'm developing a skin for Plone 3.x. The skin have a lot of differences from the default theme, and i would like to keep the default skin in administration mode. I read some solutions like this http://maurits.vanrees.org/weblog/archive/2008/01/switch-your-skin-based-on-the-url . But I cannot use subdomains in my web, so I cannot use these solutions.
I'm thinking that the solution would be something like that:
In my main_template.pt:
<tal condition:"true: Autenticated as admin">
''Put here the specifics css
</tal>
But I don't know the correct sintax in Plone
Thank you.
Your solution will work - but there are better ways. You don't describe how your stylesheets are installed, but here are two ways to do it.
Either, if you have a policy product, put the following in your product's profiles/default/cssregistry.xml:
<object name="portal_css" meta_type="Stylesheets Registry">
<stylesheet title="" cacheable="True" compression="safe" cookable="True" enabled="1"
expression="here/portal_membership/isAnonymousUser"
id="visitors.css"
media="all" rel="stylesheet" rendering="import"/>
<stylesheet title=""
cacheable="True" compression="safe" cookable="True" enabled="1"
expression="not:here/portal_membership/isAnonymousUser"
id="admin.css"
media="all" rel="stylesheet" rendering="import"/>
</object>
or; visit "portal_css" in the ZMI (Zope management interface). There you can do the same thing by "Add"ing the two stylesheets shown above, where "condition" is the value from "expression" above.
These are the same thing - one just sets it through the web, the other through GenericSetup - and now Plone will automatically incorporate one or the other css file into every page without you having to change main_template.pt. Which is something you should never, ever, do.
This doesn't answer your question directly, but you might want to take a look at "Editskin switcher".
Finally, I used this solution. The condition to detect if you are authenticated is tal:condition="not: here/portal_membership/isAnonymousUser". So, you can use a stylesheet only for visitors and other stylesheet for authenticated users. Something like that:
< style type="text/css" tal:content="string:#import url($portal_url/visitors.css);" media="all" tal:condition="here/portal_membership/isAnonymousUser" />
< style type="text/css" tal:content="string:#import url($portal_url/admin.css);" media="all" tal:condition="not: here/portal_membership/isAnonymousUser" />
Maybe this is not the optimal solution, but it works for me

Categories