I just bought from a marketplace a template for my site. The thing is that this template has relative links to its resources (styles, images, scripts, etc). Of course, all the links are currently broken. My question is: what could be the best approach to fix these links?.
I don't thing that setting all the links to {{ STATIC_URL }} be a good idea since this template has a lot of files, resources and links.
Note: When I say "template" I'm meaning a folder with a lot of HTML, CSS and images files.
Thanks in advance!
Update:
This is how my problem looks: https://www.dropbox.com/s/gbtfjaaaqxw7coo/error.png
Solved, I just added to my urls.py this:
urlpatterns += patterns(
'django.contrib.staticfiles.views',
url(r'assets/(?P<path>.*)$', 'serve'),
)
And set STATIC_URL = 'assets/'
Related
in flask templates, we combine HTML pages using extends, but my view(HTML) files are in diff folder. so how u can extend that? how to set a path? eg: {% extends 'NavigationEG/layout.html' %} NavigationEG is my folder but this way not work
without a folder, it works but I want to store it in one folder.
Like bergp said in this related question on stackoverflow, flask is looking for templates in the given templates folder. If you want to reference a different folder in your template, you could remove the template_folder when initlializing the app and refering to the full path in the render_template parameters.
Depending on the reason for the different folders, blueprints can have their own template_folder as well.
I hope this helps. If not, please share your file structure and parts of the code so we can help you find the source of this problem. Good luck.
I'm trying to extend django's admin change_form.html (django/contrib/admin/templates/admin/change_form.html).
What makes this more complicated for me is that I've installed grappelli, which also extends it (grappelli/templates/admin/change_form.html)
Now, I want to change it in myproject (to apply for all apps/modules in my project), and have tried to place change_form in various places but to no avail:
myproject/templates/admin/change_form.html
myproject/templates/grappelli/change_form.html
myproject/templates/admin/grappelli/change_form.html
Does anyone have a clue about where I should be placing my modified version of change_form.html in order for django to actually use it?
(any help on understanding django's search path & template extension mechanism will be appreciated).
Thanks!
You can include your template directory to TEMPLATE_DIRS
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'myapp/templates/'),
)
This way you can change the order in which Django reads your template files.
I finally got around to trying out django-devserver. It's installed and working but static files refuse to load (Django 1.3). (Note: static files work fine with the standard runserver management command, before switching to django-devserver, so all the configuration settings are fine.) I came across this bit in the README:
DEVSERVER_IGNORED_PREFIXES = ['/media', '/uploads']
A list of prefixes
to surpress and skip process on. By default, ADMIN_MEDIA_PREFIX,
MEDIA_URL and STATIC_URL (for Django >= 1.3) will be ignored (assuming
MEDIA_URL and STATIC_URL is relative)
Which seems very odd because the whole point of using runserver is to not have to have an actual real web server setup, especially just to serve static files in development.
Oddly, though, even though it mentions ADMIN_MEDIA_PREFIX, I found that the admin actually loads all its static resources fine, which leads me to believe that maybe I'm just missing something somewhere.
Anyone ideas?
From the URL in #MarkLavin's comment, I actually came across (rather, reminded of) the following:
# Add to end of urls.py
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
That will allow the static files to be served and is ignored in production, so there doesn't seem to be any side effects to the approach. However, it irks me a little to have to modify my urls.py just for this, but it's probably only temporary until the noted pull request is merged.
If anyone has any other solutions, feel free to add them, though.
I'm a complete newbie to apache, so the the whole deployment process has been a pain in the backside, so bear with me.
I'm having the problem of my admin site using the css formatting, it's just coming up as plain html.
I know there are other questions that answer this issue here and elsewhere, but for the life of me I can't figure out to get it working. So if anyone can spot what I'm messing up I'd be eternally grateful.
The relevant lines in settings.py are:
STATIC_ROOT = '/var/www/logparseradmin/logparser/static'
STATIC_URL = 'http://theyard/logparseradmin/static/'
ADMIN_MEDIA_PREFIX = '/var/www/Django-1.3.1/django/contrib/admin/media/'
and I have:
Alias /static/ /var/www/Django-1.3.1/django/contrib/admin/media/
in my httpd.conf.
I've tried a whole bunch of variations on this, as the various answers on the Internet have suggested, but no luck.
Thanks very much.
There's at least three things wrong here.
Firstly, your STATIC_URL is not probably a valid URL - http://theyard/ is not a real domain name, and won't work unless you've got local DNS resolution (which, given your self-described newbie status, seems unlikely.)
Secondly, the path value of STATIC_URL doesn't match the Alias you've put in httpd.conf - STATIC_URL has /logparseradmin/static/, whereas Alias just has /static/
Thirdly, ADMIN_MEDIA_PREFIX should be a URL path, not a file path.
And without seeing the rest of your http.conf it's impossible to be sure, but there may be fourth issue with mod_wsgi matching the URL before your Alias is processed.
https://docs.djangoproject.com/en/1.3/howto/static-files/
Trying to serve static files i was put on to the above link.
The link tells me when serving static files in development
Put your static files where they will be found, 'home/jamie/mysite/static/'
Done!
2.Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.
For local development, if you are using runserver...you’re done with the setup.
Done!
3.You’ll probably need to refer to these files in your templates. The easiest method is to use the included context processor which allows template code like:
<img src="{{ STATIC_URL }}images/hi.jpg" />
Done!
Wow, that seems too simple, surely it wouldn't work,
and sadly, no.
{{ STATIC_URL }} when i checked, equals None. Now STATIC_URL by default is none, therefore these instruction haven't done a thing. Surely i've done something wrong and the django documentation is right. But i cant figure out where in the three simple steps i've gone wrong.
Try setting STATIC_URL = '/static/' in your settings.py.