Static files apply on all pages except index.html and base.html - css

I have an issue with static files. I uploaded the code on pythonanywhere, it runs, and I correctly linked the static URLs in pyanywhere>web page. the problem is that my static does not load on the index and base.html but on the other pages (where I have base.html extend it applies). Can you give me some support, please?
how it looks
python anywhere url
STATIC_URL = 'static/'
STATIC_ROOT = "home/Tsh2Dns/businessplaner/static/"
#i tried to give root from pythonanywhere. still same response
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),
]
STATICFILES_DIR = [
os.path.join(str(BASE_DIR.joinpath('static')),)
]
folders:
here is the base
base
enter image description here
landing page.
all the other pages have the same beginning with base extend.
I have to mention that on my local it works just fine, only on pythonanywhere this happen

Related

Serving static files in an HTTP server

I'm using golang as the backend for a medium-sized web app which has a few pages and a lot of CSS and javascript in different folders, I'm trying to serve the website using golang but only the index file loads , the other pages, javascript, CSS doest load. since my HTML files, all are different from each other I'm not using templates
here is the file structure
-static
-assets
-css(folder with subfolders)
-js(folder with subfolders)
-pages (folder with differnt html pages)
-signup.html
-dashboard.html
-index.html
-register_bundle.js
-main.go
func handlerequests (){
myRouter := mux.NewRouter().StrictSlash(true)
myRouter.Handle("/", http.FileServer(http.Dir("./static")))
myRouter.HandleFunc("/transaction", transactionHandler)
log.Fatal(http.ListenAndServe(":8080",myRouter))
}
my HTML files have links like these, (showing index.html)
<!-- CSS Files -->
<link href="./assets/css/bootstrap.min.css" rel="stylesheet" />
<link href="./assets/css/paper-dashboard.css?v=2.1.1" rel="stylesheet" />
<!--JS files -->
<script src="./assets/demo/demo.js"></script>
<!--Main Script file for the page -->
<script src="./register_bundle.js"></script>
errors shown here
The problem is browser cannot find those JS and CSS files.
fs := http.FileServer(http.Dir("./static"))
MUXRouter.Handle("/", fs)
MUXRouter.PathPrefix("/assets/").Handler(fs)
MUXRouter.PathPrefix("/pages/").Handler(fs)
MUXRouter.Handle("/register_bundle.js", fs)
That way a GET request to http://[host]:[port]/css/style.css will return style.css from the relative ./static/css/ directory. The above code is working in my sample program.
try
gor:= mux.NewRouter().StrictSlash(true)
fs := http.FileServer(http.Dir("./static"))
gor.PathPrefix("/transaction").Handler(fs)
it probably should work if it doesnt just try reading documentation for http.FileServer
did you try serving a handler fot your resources folder?
sdir := "/resources/"
myRouter.PathPrefix(sdir).Handler(http.StripPrefix(sdir, http.FileServer(http.Dir("."+sdir))))
this allow you to access the foloder as a subdomain.

I don't understand why the css and the images are not seen in phplist

I've installed phplist in a folder in public_html folder in my site
http://www.parcuri.ro/news/
It's working, but the images and the css are not "used"
The paths in config file are
$pageroot = '/news';
$adminpages = '/news/admin';
Why is this happening?
When I try to access your css or images, I am getting redirected to your homepage. I am assuming this is your 404 page so the CSS and Images dont "exist". This means your file paths are wrong or you have not saved the css/images in the right area.
Perhaps your images/css are stored in http://www.parcuri.ro/styles rather than http://www.parcuri.ro/news/styles.

point to a custum setting in the template

I want to create settings in the settings.py file that i can access in the templates that i use without passing the setting in ,in the views.py using django
settings.py
CSS_FOLDER_ROOT = "/home/brian/Projects/RaffleThis/RaffleGym/stylesheets"
CSS_FOLDER_URL = SITE_DOMAIN + "/CSS/"
I want the server to serve the files from CSS_FOLDER_ROOT when HttpRequest is sent
working on the django template .html file and the views.py file
I guess one way to do this is by creating a context processor.
Create a context_processors.py somewhere in your project
import settings
def css_url(request):
return {'CSS_URL': settings.CSS_URL}
Add the context processor in your settings
CSS_FOLDER_ROOT = "/home/brian/Projects/RaffleThis/RaffleGym/stylesheets/"
CSS_URL = '/css/'
TEMPLATE_CONTEXT_PROCESSORS += (
"django_app.context_processors.css_url",
)
Then you can use something like this in your templates.
<link rel="stylesheet" href="{{ CSS_URL }}<filename.css>" />

Visual Studio and ASP.Net Path question

Question about paths while working in Visual Studio. In my master page I have some paths to load css files as well as javascript files.
My first question is if I use relative paths, should the relative path be from the location of the master page file? For example if I keep all my master page files in a folder off the site root called MasterPages should I assume that is the starting point for my relative paths to load the css files? If that master page is used to wrap an aspx file several directories down the tree is the hard coded relative path still valid?
Second question, is there a way to use absolute paths so that everything works on my local machine as well as when I move the files up to the webroot? For example my app path on my local machine may be localhost/myappdir/default.aspx but when i move the app to the server there is no myappdir and the default.aspx is in the webroot. I do not want to have to change paths in the files after they are moved up to the server.
currently I have..
src="<%= VirtualPathUtility.ToAbsolute("~/lib/css/style.css")%>"
but this way Visual Studio cannot find the css file to update intellisence
If you use relative paths to your css/Javascript files, then they will need to be relative to the page, not the Master page.
This article does a very nice job of explaining the options you have in this situation, and towards the end they propose a nice solution to this type of problem, a user control that renders the script or link tag for you and calls ResolveClientUrl to make the paths correct.
As a rule, you should be using server-relative paths (as in, /images/stuff.gif) to everything all the time. Using relative paths (as in ../images/stuff.gif) will screw you every single time, as will trying to rely on ASP.NET "Magic" such as VirtualPathUtility.ToAbsolute and ResolveClientUrl.
Occasionally, on the server you'll need to prepend that path with a tilda (as in ~/images/stuff.gif) so that it will correctly navigate the virtual directories that ASP.NET requires you to base all your projects in.
Naturally, this also means that you'll need to set your dev box up with multisite so that you can change your root to something like http://mysite.dev/ and ensure that all your server-relative paths work correctly. (Using the VS.NET built-in server would technically work around that too, but really, do you want to use that thing???)
Use the "~" operator to resolve everything relative to the root. Never use relative paths. Even when I'm not using themes, I use their syntax to get simple syntactic access to my CSS files by creating a folder structure like : App_Themes/Style/stylesheet.css Then in my ASPX page directives I add Theme="Style" and my CSS files will be automatically resolved - not exactly conventional but very effective :-)
UPDATE:
To resolve the JS, you could use the following in your master page code-behind:
string myScript = "js/footerFix.js";
Page.ClientScript.RegisterClientScriptInclude("myKey", myScript);
With IIS7 you do not need to change anything to get "multi-site" behaviour; this is baked in. For example you can have several sites as follows and reach them via URL without any separate configuration aside from creating the virtual directories:
localhost/project1
localhost/project2
localhost/project3
Put your script and stylesheet links in a <head Id="headRegion" runat="server" /> in the master page. Their src/href should be the absolute URL path that you get when running in WebDev.WebServer (eg /ProjectWeb).
In the Master Page OnPreRenderComplete(), rewrite any URLs inside headRegion.
Visual Studio can intellisense your scripts and css, and the project can be deployed under any virtual path.
protected override void OnPreRenderComplete( EventArgs e )
{
base.OnPreRenderComplete( e );
var root = Request.ApplicationPath;
if (root == "/") {
root = "";
}
foreach (Control c in headRegion.Controls) {
if (c is HtmlLink) {
HtmlLink hlink = c as HtmlLink;
hlink.Href = ReplacePath( hlink.Href, root );
} else if (c is LiteralControl) {
var literal = c as LiteralControl;
literal.Text = ReplacePath( literal.Text, root );
}
}
}
string ReplacePath( string content, string prefix )
{
return content.Replace("/ProjectWeb", prefix );
}

ASP.NET Setting Flash file path for Object tag inside a usercontrol

I have a an ASP.NET user control where i wanto run a flash movie using flashplayer.How can i set the path of flash movie file properly so that this would work in all pages irrespective of the folders. ie; it should work inside a page in FolderA and a page in FolderASub1 which is in FolderA and a page in the Root folder too.My Flash file resides in a Folder called FlashGallery in root.My User control resides in a Subfolder in Root.
I am not sure how can use ~ here .Since its(Object tag to play flash) not a server control.
And infact i cant place the full relative path too.
Anythoughts ?
You can use a root-based path: /FlashGallery/movie.swf
Or you could generate a path string in your code, and place it in the aspx file like this:
Use an absolute path based off the root of your domain. Instead of using a relative url path like
"mymovieplayer.fla"
or
"../mymovieplayer.fla"
do this
"/flash/mymovieplayer.fla"
FYI: I use this (Free)Control: http://www.junasoftware.com/servercontrols/swfobject.net/download.aspx
You can use the '~' tilde to use relative paths to the site root and it will work on a master page, even if content pages are in different directories, you can use it like this:
<%# Register Assembly="SWFObject.Net" Namespace="Juna.Web.UI" TagPrefix="SWF" %>
.
.
.
Its FREEEEE!
Using a root based path is fine if you always know your site will be installed to the root, but this isn't realistic and best practise.
It would've been nice of we could use the server side relative path prefix of ~/ for the ... tag, but as you know it's not a user control so it just gets rendered out to the client as is. Below is a trick to allow you to specify the ~/ relative path for a client side script block.
I essentially use the VirtualPathUtility class and a protected method on the code behind of the page, master page, or control and it works very well for me.
Here's the method:
protected string GetPageRelativePath(string targetPath)
{
return VirtualPathUtility.MakeRelative( Request.AppRelativeCurrentExecutionFilePath, targetPath );
}
And here's how you can use the ~/ prefix in the script block:
<script type="text/javascript" src='<%=GetPageRelativePath("~/Scripts/MyScript.js") %>'></script>
Essentially you could use this with other src paths, even paths to images or Flash files.
Hope that helps.

Resources