I have a static folder set in django to a network path
STATICFILES_DIRS = [
"//SERVER/Shared1/FOLDER_210121/",
]
and I have 2 pages that have links to this static subfolders
link1: http://server2:8044/static/folder1/COINS_LIVE_OU164/user1310200781810167.tif
link2: http://server2:8044/static/folder2/COINS_LIVE_OU164/user2310200781810167.tif
however link1 works perfectly but link 2 gives me an error as file not found
but the file does exist, and from IIS I have set a virtual directory aliased as "static" with the root folder that contains the subfolder from where I get the files.
I can navigate from the virtual directory to both files, the virutal directory was created with the defaultAppPool user.
is there something else I could check?
(if I run the manage.py runserver command and I use localhost I can download both files, the issue is when using it from the IIS).
if I print the value of static in a label the path is ok, so I'm guessing permission, but where can I be missing the configuration?
Thank you.
Adding a bit more info:
the issue affects a subfolder inside the "static" folder, 1 can enter without probelms, the other can't.
I'm getting crazy. I deleted all, created again, and the issue still occurs.
I was able to solve my particualr problem, it was fixed by putting the static handler module mapping alone with the Django FastCGI (custom) module in the website IIS
Related
We are facing a very weird issue. We ship a django application in a docker container through Github Actions on each push. Everything is working fine except collectstatic.
We have the following lines at the end of our CD github action:
docker exec container_name python manage.py migrate --noinput
docker exec container_name python manage.py collectstatic --noinput
migrate works perfectly fine, but collectstatic just keeps on waiting if ran through the github action. If I run the command directly on the server then it works just fine and completes with in few minutes.
Can someone please help me figuring out what could be the issue?
Thanks in advance.
Now I am far from the most experienced but I did this recently and I have some suggestions of where to look. I'm definitely not the greatest authority though.
I wasn't using docker so I can't say anything about that. From the issues, I had here are some suggestions I can recommend to try.
Take note that all of this was for a self-hosted runner. Things would be very different otherwise.
Check to make sure STATIC_ROOT and MEDIA_ROOT variables are set correctly in the settings file.
If the STATIC and MEDIA root variables are environment variables make sure you are serving the correct environment variables file like a .env file which I used.
I used django-environ to serve my environment variables. From the docs, it says to have the .env file in the same directory as the settings file. Well if you are putting the project on a production server with github actions, you won't be able to put the .env file anywhere in the project because it will get overwritten every time new code is pushed.
So to fix that you need to specify the correct .env file from somewhere else on the server. Do that by specifying ENV_PATH.
https://django-environ.readthedocs.io/en/latest/
Under the section Multiple env files
Another resource that was helpful:
https://github.com/joke2k/django-environ/issues/143
I set up my settings file like how they did there.
I put my .env file in a proj directory I made in the virtualenvironment folder for the project.
I don't know if it's a good place to put it but that's how I did it. I didn't find much great info online for this stuff. Had to figure out a lot on my own.
Make sure the user which is running the github action has permissions to read the .env file.
Also like .env file, if you have the static files being collected into the base directory of your project you might have an issue with github actions overwriting those files every time new code is pushed. If you have a media directory where the user uploads files to then that will really be an issue because those files won't get overwritten. They'll just disappear.
Now if this was an issue it shouldn't cause github actions to just get stuck on the collect static command. It would just cause files to get overwritten every time the workflow runs and the media files will disappear.
If you do change the directory of where the static and media files are located as stated before, make sure all the variables for the paths are correct in the settings file and the .env file.
You will also need to update the nginx config file for the static and media root directories if you used nginx. Not sure about how apache does this.
You can do that with this command:
sudo nano /etc/nginx/sites-available/myproject
Don't forget to restart the nginx server after doing that.
If you are writing static and media files at a different location from the base project directory on the server, also check permissions on those directories. Make sure the user running the github action has permissions to write to those directories. I suspect that might cause it to hang but it very well might just cause an error.
Check all the syntax in the github actions yml file. Make sure everything is correct and it's not hanging cause it had an incomplete command or something like that.
But yeah, that's some things I had to take a look at. Honestly, none of this might be relevant for you. All of these issues should cause an error somewhere for the most part.
I couldn't really offer many external resources for you to look deeper into this because I'm just speaking from personal experience.
Hope I could help.
Heres my github repo for the project I did: https://github.com/pkudlanov/personal-portfolio-django
I hosted it on digitalocean on a linux server using nginx and gunicorn.
I deployed a django app on AWS EC2 every page is working but the login page and detail view page returning a 'template not found error while both of the views working on my machine.how can i fix this ? i already see it has to do something with my virtual machine.
to keep in mind here's my folder structure :
/Eyelizer
/app1
/app2
/Eyelizer
/eyelizerenv
/etc
I use this folder structure as it has something to do with the nginx and gunicorn configuration.
The problem was that Unix systems are case sensitive. my files in the directory was Login.html and patient_detail.html while calling them in my .py files was different as login.html so by renaming the files it worked.
With django (python server) is possible to add more that one path to serve static files using STATICFILES_DIRS = ("C:/some/path/static_two",) on settings file, and works fine, but on production server, in my case IIS, is that possible?
I tried adding two virtual dirctories each one whit different paths/locations, but doesn't works, the static file from the second directiry "C:/some/path/static_two" doesn't shows.
Someone can help me on how configurate IIS two serve static files from more that one location.
thanks in advance.
You are confused about what that setting does.
STATICFILES_DIRS is the place(s) where static files are copied from when you run manage.py collectstatic. The place they are copied to is STATIC_ROOT, which is a singular directory. You need to set up your web server to serve files from there, not from STATICFILES_DIRS.
I am using Django and Apache.
I am serving the static files with Apache. It works well, the problem is, when a user go to the url http://urlOfMySite.com/static, he can see the whole directory and navigate in it.
I'm using : Alias /static /var/www/MySite/app/app/static in Apache VirtualHost to serve static files.
Is there any way to hide it from user? (make the static files accessible, but not the full directory browsable).
Thanks
Your problem is about the apache server itself, you need to disable indexing for that folder with "Options -Indexes" inside the "directory" clause to specify which folder you want to apply this command. More info:https://wiki.apache.org/httpd/DirectoryListings#Directory_Listings
Btw, this is odd, by default, when I deploy using Apache, I don't need this =/.
Target WSGI script not found or unable to stat: /opt/python/current/app/application.py
I contain my app in a file called application.py, and my application's configuration looks like this:
I also tried uploading the sample app that AWS provides, which only contains 'application.py`, and yet I still get this error.
What could be causing the error?
For me, it was this silly thing. In my mac, I compressed by right-clicking on the folder/repository and compressing it to zip. However, a zip like that extracts to open another folder within it which contains the application. As a result, EBS is unable to locate application.py.
The simple fix hence was to select all the individual files inside the folder to create the zip file for uploading (or using the EB CLI to upload).
I had a similar issue. You should put your application.py in root directory as your WSGIPath suggests, or change your WSGIPath in .elasticbeanstalk/optionsettings.yourappname-env.
For me, I had my app instance stored in a variable called app, which wasn't recognised by Elastic Beanstalk. As soon as I changed the variable to application, it started working.
# In application.py or manage.py, after initialising the app
application = app
should do the trick.
Use application instead of app or any other variable you are using.
application = Flask(__name__)