I have to debug some existing Django project build me other develeopers.
In my local developement environment all the static files have path like
/static/myapp/module/user.js
But when i see the html of testing on tetsing server then i can see the files like
static/myapp/module/user.42323gdb.js
Now i want to know why the system is using that file instead of user.js.
Is there any setting which i can fix or it is meant to do like that
Seems like your project uses one of the asset managers. I suspect you can find it in the INSTALLED_APPS setting.
UPDATE: By default the django-pipeline does this magic then the DEBUG = False. Which is the case for your development environment.
The other setting to enable/disable the pipeline is the PIPELINE_ENABLED. So you can have the "normal" file names on the production server too. But I suggest you to leave the pipeline enabled :-)
Related
I have a settings.py file for my Django project that reads in environment variables for some fields. This works great for local development. I'm not sure of how to make this work for my Jenkins build (Freestyle project). An extra layer of complexity is that some of these variables contain sensitive data (passwords, etc.) and so need to be secured.
So far, I have been able to use Credentials Binding Plugin to set up a secret .env file and can successfully access that as an environment variable.
How do I go about setting all the 'actual' variables from that file? Or is this bad practice?
If it's not bad, wouldn't those variables continue living on the server after the build has finished?
If it is bad, what is the better way to do this? I can update the settings.py file easily enough if needed to make this work.
Maybe using something like django-environ is the right approach?
include(
# the project different envs settings
optional('envs/devel/*.py'),
optional('envs/production/*.py'),
optional('envs/staging/*.py'),
# for any local settings
optional('local_settings.py'),
optional('path.py'),
)
What should be the folder structure I follow to build Django web application, I did not found any repo on github in which contains files that are made according to the environments. As i am moving from php to python i did not found how to exactly define the constants in python so that the value of the constants will not change anywhere.
print("currently i am using django-split-settings to include files")
when using django you do not do this. rather in the settings.py file. you check whether the debug flag is true or false i.e. whether the project is in production or not. to change the settings for development/deployment.
hosting on github
when you host it on github any thing is fine as long as you add a requirements.txt
to allow you to install the requirements on another machine. its a good rule of thumb to not use virtualenvs on different machines so it is rare to see them on github repos.
We use Django for a project. Prior to 1.7+, we were able to dynamically pull in files to our python environment when setup.py was being executed. For example, we have this directory structure:
/foo/bar
/foo/bar/__init__.py
/foo/bar/my_functions.py
Our Django project doesn't know anything about those files to start off. When the web server starts and setup.py is read, we look at a configuration which tells us where to find files to add to our environment. Again, let's assume /foo/bar is in our configuration to be dynamically loaded. We would then use import_module() to import it so that anything under /foo/bar essentially becomes part of the project and can be used. It's basically a "plugins" feature.
After Django >=1.7, this causes huge problems, mainly:
django.core.exceptions.AppRegistryNotReady: The translation infrastructure
cannot be initialized before the apps registry is ready. Check that you
don't make non-lazy gettext calls at import time.
It also limits our ability to add new files dynamically as you always have to put them in place and restart your web server. You couldn't have an "Upload Plugin" page to add new files to the server, for example.
Is there a way to add files like this both during the web server startup as well as after the startup without restarting it?
I currently have a running production Django application on Heroku. Unfortunately, I haven't been able to turn off the DEBUG setting on Heroku. Turning it off locally works fine, but when pushed to Heroku (after heroku config:set DEBUG=False), it doesn't apply.
The error pages are still the default DEBUG ones instead of the 404, 403, and 500 templates in our template root.
I have also tried using a DJANGO_DEBUG setting in case there were any environment conflicts with DEBUG, and casting the result to a boolean in the settings file. heroku config shows the settings in the environment are correct. This is on Django 1.3, Heroku Cedar.
Any tips or solutions?
Does your django settings.py file even look in the environment?
It does not, by default, care about anything you've set in the environment (via "config:set"). If you're "casting" the environment to a boolean, make sure you're casting it correctly. bool('False') is still True.
It's simplest just to detect if the environment variable exists so you don't have to worry about type casting or specific formats of the configuration.
DEBUG = os.environ.get('DEBUG', False)
To disable debug, remove the variable from the environment instead of trying to type cast... it just seems much more reliable and fool proof. config:unset DEBUG
The problem is that the environment variable is not a boolean, rather a string.
So do place below line in settings.py
DEBUG = (os.environ.get('DEBUG_VALUE') == 'True')
I'm trying to setup a second development environment for my project. I've copied over the settings from the working setup but on the new one the URLs generated by the Django admin are prefixed with /admin/. This does not happen with the other setup at all.
More details:
I'm using django-grappelli for my admin panel.
The generated urls on the working setup are of the kind /static/grappelli while on the not-working one they are of the kind /admin/static/grappelli.
Disabling grappelli yields no fix either, the urls are then of the kind /admin/static/admin.
I'm using Django 1.5, it uses a git repository for the source files and a frozen pip requirements.txt. I can only conclude that version differences are highly unlikely.
Other static files work fine, only the admin related ones are hit with this.
My URL settings are the following:
STATIC_URL = '/static/'
MEDIA_URL = '/static/media/'
The *_ROOT ones are not set due to use of development server.
I'm out of ideas as to why this is happening on only one of the servers with the same setup.
edit:
Removing the /admin/ prefix allows you to properly access the files. The finder is fine, but the urls generated are just wrong.
The fix is very simple, the STATIC_URL setting should always contain the first /. It seems the Django admin prepends /admin/ if there is none.
I had a faulty settings file overwriting my default STATIC_URL, always check your settings first!