Nginx Static files for Flask Admin Page - nginx

I have trouble serving the static files for flask admin page.
admin = Admin(app, name='APPName', template_mode='bootstrap3')
app.config['FLASK_ADMIN_SWATCH'] = 'Slate'
Everything seems to be working on localhost but when I upload the application to the server(ubuntu) the bootstrap template no longer works.
The route to the static files for the Flask admin is
http://127.0.0.1:5000/admin/static/bootstrap/bootstrap3/swatch/Slate/bootstrap.min.css?v=3.3.5 on localhost.
On the server its https://domainname.com/admin/static/bootstrap/bootstrap3/swatch/Slate/bootstrap.min.css?v=3.3.5 but its returning error 404.
Can anyone can point me to the right direction.

I know this probably comes late, but here:
Solution
Change your second line:
admin = Admin(app, name='APPName', template_mode='bootstrap3')
app.config['FLASK_ADMIN_SWATCH'] = 'slate' # This line: 'Slate' to 'slate'
Context
I was having the same issue you did. In my case, my config file contained this:
# Flask Config
FLASK_ADMIN_SWATCH: str = "Superhero"
Worked locally, but not when deployed to an EC2 machine running CentOS, I got a 404.
I was running Windows locally and a Linux-based remote machine. I bet you are as well. Windows is case-insensitive, while Linux is case-sensitive.
Having the FLASK_ADMIN_SWATCH variable set to Slate means the path that arrives at flask is something similar to admin/static/bootstrap/bootstrap4/Slate/bootstrap.min.css?v=4.2.1. This doesn't present an issue for Windows, but it does for Linux.
Swatch themes reside inside flask_admin/static/bootstrap/bootstrapX/swatch/, each of them on a folder of their own, and all of them lowercase (e.g.: cerulean, cosmo, etc.). Your specific theme directory is flask_admin/static/bootstrap/bootstrapX/swatch/slate/.
Windows will try parsing bootstrap/bootstrap4/Slate/bootstrap.min.css?v=4.2.1 and succeed at it, because it doesn't care for the case-ness of Slate, but Linux does, that's why it fails and ends up returning a 404.
# These paths are equivalent for Windows, but not for Linux.
bootstrap/bootstrap4/Slate/bootstrap.min.css?v=4.2.1
bootstrap/bootstrap4/slate/bootstrap.min.css?v=4.2.1

Related

Django project does not work after being transferred from Windows to Mac

I'm using Django 3.1.7 on a MacBook Pro after transferring the Django project off of a Windows 10 machine. However, upon re-setting up the database and superuser and running the command pipenv sync to install all necessary modules, the server does run; but it doesn't serve any of my URLs or the CSS styles for the Admin page. I can reach the admin page at '/admin' but no other page that I've set up will display. All it gives me is my custom 404 page whenever I try to serve a page. Is there any way to fix this? Is something wrong? Where are the Admin CSS files?
python manage.py runserver --insecure
Use the --insecure option to force serving of static files with the staticfiles app even if the DEBUG setting is False.
djangoproject
I think we'd need more information... maybe the files itself.
There could be tons of things that could go wrong. Is your settings.py still pointing to the correct file paths? In views.py, did you make sure you are setting the html files in the same path? Are the html files in the right folder? Are all the Django and module versions the same? There's too much to name.
I have the same problem.
By what you are describing it happens because your file path uses either / or
One machine uses forward slash and the other backwards slash
I dont know to so use a method that work on both

How to deploy a polymer 3.0 build on NGINX (Raspberry Pi)

How can I configure the Polymer build so I can deploy my app built on Windows to my Raspberry Pi running NGINX (in a sub directory)?
I could not install polymer-cli directly on my Raspberry Pi since the chromedriver (which polymer-cli needs) is only available for 64 bit Linux and the official Raspian OS is currently 32 bit only.
So I installed polymer-cli on my Windows machine, and created my first Polymer app according to https://www.polymer-project.org/3.0/start/toolbox/set-up, I also created the new-view page.
I can now run the app using polymer serve (which shows the app correctly in the browser on the Windows machine) and build using polymer build. Now I want to deploy so I copied the build directory (which contains three built variants, es5-bundled, es6-bundled and esm-bundled) to a sub-directory of the NGINX root, /var/www/html/polymer/build.
Firing up my browser and pointing at http://<raspberrypi-ip>/polymer/build/esm-build I see two errors.
The src="node_modules/#webcomponents/webcomponentsjs/webcomponents-loader.js" and src="src/my-app.js" in index.html gives 404. I could not find how to configure polymer-cli to change these, and still serve a working app in Windows so I manually added polymer/default/ to those two paths in the index.html.
Now I end up with a grey page in my browser, no further error messages...
Moving to my phones browser and entering the same url, http://<raspberrypi-ip>/polymer/esm-build, I actually see my app, together with an Oops you hit a 404. Head back to home link. following that link I get to my app, which seems to be working - but the URL is now http://<raspberrypi-ip>/new-view.
I've also played with the NGINX try_fileswithout luck...
server {
...
location /polymer/default {
try_files $uri /polymer/default/index.html =404;
}
}
EDIT: In Serving Polymer App to a /path not at root I found out that I also need to adjust rootPath in index.html. However I still get the 404 described above if I point my browser at http://<raspberrypi-ip>/polymer/esm-build/index.html...
Also, is there any way to refer to the rootPath in the <script src="">tag I manually edited above?
This is my first encounter with Polymer and NGINX, so any pointers are appreciated.

MAMP Start Page Only Shows Index

I'm trying to install Wordpress on MAMP using this tutorial. When I start the MAMP server and go to the MAMP startup page, I see this index instead of a GUI. As a result, I can't access the PHPMyAdmin GUI (despite the PHPMyAdmin link) to create a database for Wordpress. Does anyone know what I might be doing wrong? I'm running OSX 10.9.5.
Try that url to access phpmyadmin
http://localhost:8888/phpmyadmin/
This is the directory listing that Apache provides in some cases. When a folder is requested, Apache looks in a folder for a file name matching the DirectoryIndex directive, which are often files such as index.php, index.html, home.htm, and so on. Since none of those exist here, the directory listing is shown.
Basically, something isn't right here with your MAMP install; either this URL is not designed to be accessed by you ever or your installation is incomplete. First, try loading http://localhost:8888 directly and see if that works any better for you. Failing that, I suggest you make a backup of any MAMP related files (databases, web pages, or configuration changes) and reinstall. One possible cause of this is if the MAMP package is not installed to /Applications/
In short, when you're using an all-in-one package like MAMP this shouldn't happen. You say that when you uninstalled and reinstalled that fixed the problem which is what I would have suggested anyway. It seems something went wrong with the installation and that should (and did) fix it.
I add the solution that helped me in the similar situation just in case someone later will face the same problem when after the Wordpress has been installed, a browser just show "Index of/" instead of the required site.
Check the following points:
There is 'index.php' file in the root folder of your project. (web server tries to open exactly this file).
If the file actually is located there, check the configuration of your web server. For example in my case my web server is Apache 2.4. After I added the directive "DirectoryIndex index.php" in the Apache configurations file (thereby saying to the server which file it should open if it received the address of the root folder) my problem was solved.

System.Web.Optimization bundles are empty when running in a virtual directory

I'm having problems when deploying my application to a server using a virtual directory in IIS.
I have configured the same files to run under the default website in a virtual directly and also in a new website root running on port 81. Both configurations use their own identical app pools. While the site on port 81 works fine the site running in a virtual directory doesn't load the bundles.
In the page I see links with missing versions in the URL, such as:
<link href="/MyVirtualDir/Content/css/site?v=" rel="stylesheet">
The URL returns a 200 status from the server, but the content is completely empty.
I have looked on SO at questions like this which references this bug ticket but my understanding is that this is when the files being included in the bundle are 'virtual' or not under the physical folder root. Which is not true in my case.
Cheers for any help you can give me. I can't believe that this configuration wouldn't be supported so I must be doing something wrong somewhere!
Update:
I think a ticket describing my problem has been raised on the web optimisations codeplex site here http://aspnetoptimization.codeplex.com/workitem/55 Not that this gets me any further though :(
After comparing with a new project I tracked down the problem:
I was using T4MVC (trying to be clever and not use 'magic strings' in my code). So I was using a link such as
bundles.Add(new ScriptBundle("~/Scripts/all")
.Include("~"+Links.Scripts.Library.jqueryPlugin.jquery_ui_js), ...));
When this runs under a virtual directory it will resolve with the virtual directory name in the path, so it can't find the files.
I hope this helps someone else who runs into the same problem. Also, it looks like T4MVC are looking to improve the use of magic strings in bundles in future releases. See here for a discussion

Local Coldfusion server for multiple domains / URLs

I want to get CF9 with IIS 7 setup locally to run with multiple domains.
I have read this one but it doesn't say anything about the actual setup.
Need help with multiple URL setup on local CF9/Jrun install
I setup IIS so that I can start 127.0.0.1/domain1/index.cfm The page loads properly
but all subsequent links fail with
Could not find the included template: /_/definesession.cfm
But I see the file when typing in file:///C:/InetPub/wwwroot/domain1/_/DefineSession.cfm
The files are there but apparently the server is only reading the directory correctly
If I test http://127.0.0.1/domain1/_/BrowserDetect.cfm with no includes just a self contained file it executes properly.
The path in IIS is set to C:\InetPub\wwwroot\domain1
The bindings hostname is just domain1 no TLD
Also the second instance 127.0.0.1/domain2/index.cfm is working correctly. And here as well including subdirectories is failing.
ADDITIONAL NOTES: (added 1/3/12)
I guess it has to do with the CF mapping. I now moved the code to c:\coldfusion9\wwwroot\domain1_... and it sort of works.
In other words I start the program here: C:\inetpub\wwwroot\domain1\index.cfm Inside that index is for instance
But it executes the file located here: c:\coldfusion9\wwwroot\domain1_\definesession.cfm Just couldn't find anything in the web about mapping a local CF9 to that situation. Any idea??? –
You might have a ColdFusion mapping for "/" that needs to be adjusted.
OK I fixed it. There were multiple issues:
For whatever reason there were some issues with IIS and I had to reinstall it.
I had to make sure 9.0.1 was installed
I had to run Webserver Configuration Tool multiple times to actually get the Handler Mappings in order.
http://127.0.0.1/domain1/ was wrong - it must be http://domain1/ etc.
I forgot to add the domains to the host file on the machine - stupid me
I had to redesign my mapping to avoid overlaps between domains (i.e. mapping CFCs to /_/cfc/ on all domains needed to have different mapping names.
Now I have several different domains on my local machine and they work just fine.

Resources