Here I am once again asking a question that might seem stupid:
I am new to web development. So far I've made some practice projects with Django and I've deployed two projects so far as github pages but they were simple static websites (no django).
Now I'm making a web application for my mom's business with Django.
I don't know what I should do with all the images I need for the website.
In the past I have uploaded all jpg and png images to imgur and copied the link in my static websites html
But now I have more images and I am going to pay for a server for them application. I have two types of images:
Images that will always appear on the page. Because that's part of the design
Images that the admin can upload when creating a new post for the page
So my question is:
Should I have all images in the statics folder for my application?
And call them like this:
<img src="{% static 'website/images/home-slider/myimage.css' %}">
And for the other images should I save a similar path in the database?
I just have no idea if things should be done different for production
Images used as a part of html files are served within static files and images uploaded by the user as a part of creating new post are saved as media files. You usually have seperate static and media root for saving files to avoid confusion.
Media files are served as '/media' as static are served as '/static'.
Related
The problem is described in title. I have this template for a blog that I'm creating using Django.
When I open it normally, using double click over the HTML file, it looks like this:
But when I open it via url from the Django project, it looks like this
It only shows a green square (part of the css) but obviously can't open the css correctly.
Any idea to solve this?
In Django you don't open the HTML with double click on the file, you need to run the server first and open your site using the localhost (like you did in the second picture).
Judging by those images, are you sure you put the image in the static folder? In Django, the HTML files stays in the "templates" folder of your app and the css, javascript and images in the "static" folder.
If this answer doesn't help you, then you should post your code here, otherwise I can't find the problem.
I have a large group of static html pages that I've generated from sphinx, and I'd like to show them on my Django site. I can connect to at least one page by putting the html/ folder form sphinx in a templates directory inside my app, and changing the urls.py file to include
url(r'^$', TemplateView.as_view(template_name="index.html")
Then it finds the index.html file inside myapp/templates/html. However, none of the internal links work (it'll try to redirect through Django and give me a 404 error). Also, the static files won't load in (Sphinx generates a _static folder, and even though I put that in the myapp directory, and the Chrome network tab tells me it's trying to load the css from myapp/_static, still nothing).
Is there any way to make all the links relative to each other inside this project? Alternatively, can I get Django to just serve up the whole project as static pages?
It looks like FlatPages is almost what I'm looking for, but I have more than just a title and content in these pages.
Firstly, you should not be using Django to serve essentially static files. This is what your webserver is for.
If you are using Apache, you can use the <directory> directive to serve these files alongside your Django routes.
Now I have a django project and some small html project (in fact, some html5 games). How can I added the html site to the django project?
For the each html project has ref a lot of css, img and javascript in its own folder, and different html site are in different folder.
Hence, I can not now just do like this:
t = get_template('htmlprojectfolder/index.html')
html = t.render(Context())
return HttpResponse(html)
I think my problem is:
"how can I jump to a html index page with its static files correct linked?" (Clealy, I can not read just the index page as a template file.)
Thank you for help!
I think the best way to add static, non-Django files that shall be accessible via a Django project would be to add the files to the STATICFILES_DIR. You can read more about static files here in the Django documentation.
Another, and possibly better, way to handle this would be to let the webserver serve the static files separately from Django.
I am working on a project in django 1.4.4, what i am trying to achieve is i have website's index pages mapped with a unique url in database. whenever url hits that url, it should load that website.
I am able to load the index.html(easy) using http://lclhst.com/landing/one-bush
But the problem is the static files that web page auto loads.
so what i have right now is (website) in media/uploads/{unique-no}/index.html and other media files. I tried to make an all url accepting view but i think django auto-tries to serve media files when requested so all the hits like http://lclhst.com/landing/one-bush/_include/images/dot.jpg are being 404'd.
i am looking for any mistake in my approach or some better approach.
The current website is running on Django, Gunicorn and nginx. I want a way to convert the current front page into a static HTML page and want nginx to serve this static page instead of going through the whole web stack. I want the front page to load faster. This can be done manually, but is there a tool integrated with Django or Gunicorn that automatically convert certain page into static and serve those pages?
put it in your /media/ folder
then just point to
some.url/media/html/some_static_html.html