I've found the solution (if anyone ever will be in need). There are 2 situations: 1. Development. For development this problem can be solved using static function. Import it in your app's urls.py: from django.conf.urls.static import static Then use it there after the urlpatterns list: if settings.DEBUG: urlpatterns += static(r'app_name/page_name', document_root=settings.STATIC_ROOT + "/inner_files_directory/") Here app_name and page_name are same as in my initial message. This string tells Django, that there is an additional static url pattern and it must be resolved using specified directory. 2. Deploy. In deploy Django should not process static files. It should be done by a dedicated web server. In my case the server is nginx. So to process these problematic files i added to the config file (.conf that is placed in /etc/nginx/sites-enabled/) next block: location /app_name/page_name/inner_files_directory { alias abs_path_to_the_app/app_name/static/app_name/inner_files_directory; } This block is similar to standard static block, but processes requests with url, that doesn't contain 'static', but contain app_name/page_name instead
воскресенье, 8 сентября 2019 г., 21:57:31 UTC+3 пользователь Михаил Брунман написал: > > Good daytime. > I've spent some time trying to find a solution to my problem, but I still > can't. > Here is my problem. > One of my html templates has a link on a javascript file, looking similar > to this: > <script type="text/javascript" src='{% static > "app_name/script_dir/script_name.js" %}'></script> > The page is returned, when asking the next url: > http://127.0.0.1:8000/app_name/page_name/ > The mode is Debug, the static is registered and turned on and the script > itself is loaded quite successfully. > But the script is a part of a complete project and it contains some > references on other .js and .css files from that project, that are also > store locally. > And when script is loading and requesting that other files, the server > respond with 404 "Not found", because their references are relative and > become like this: > http://127.0.0.1:8000/app_name/page_name/file_relative_path > instead of > /static/file_relative_path > So is there a way to translate such links from a page-relative link to a > static-relative link? > > > Best wishes, Mikhail > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eaef703d-da88-4212-8ff5-c0a43f271dd2%40googlegroups.com.