I have certain files that I want to be static on production but want to be able to write dynamically during development. So I would like to be able to execute a script to accomplish this each time the test server reloads, so that changes I have made will be taken into account, and the file gets updated. Is there any way to hook into the autoreloader to do this, or is this something I would need to do manually?
            Asked
            
        
        
            Active
            
        
            Viewed 45 times
        
    2 Answers
2
            
            
        You can add it to your settings.py which gets loaded on the devserver reload.
# settings.py
# ...
if DEBUG:
    import your_function
    result = your_function()
    print(result)
 
    
    
        Thomas Schwärzl
        
- 9,518
- 6
- 43
- 69
- 
                    Clever suggestion, and it would work if I didn't need access to models, which don't load until after the settings file. Any other thoughts? – meesterguyperson Jul 07 '17 at 16:03
1
            
            
        Ended up doing what was suggested here. In short, I just added the following to the end of urls.py.
from django.conf import settings
if settings.DEBUG:
    my_dev_reload_script()
Thomas was close, but placing this in settings makes app references impossible. Putting it in urls ensures that apps are loaded.
 
    
    
        meesterguyperson
        
- 1,726
- 1
- 20
- 31