python - Django 1.6 image upload and media path -


So I have a project on webfaction where I need to create two different environments, one server DNS and one server To static files

So when I upload an image from the admin panel, I can see that the image is placed in the root which I define but with the full path. When I return the image in my view, then I have my domain. ////////

This generates a broken link - when I go to mydomain.com/uploads/image_name, I can see the image file, even though my link is not in the root_ url Is pointing towards the full path,

Can you help me with this? I really do not understand how I can fix this image in my picture

  & lt; Img src = "{{MEDIA_URL}} {{mymodel.my_image}}" alt = "{{name}}" Width = "150" height = "200" />   

I understand that there are so many topics here, even though no one can tell me how to "upload" the way to hide or change the root route.

Works fine in my admin

  class movie (models.model): name = models.CharField (max_length = 50) def get_file_path (example, file name) : Ext = filename. Partition ('.') [- 1] file name = "% s.% S"% (uuid.uuid4 (), ext) os.path.join ('/ home / user / webapps / project / uploads /', File name: my_image = models.imageField (upload_to = get_file_path, null = true, blank = true) def __unicode __ (self): return self.name   

In my settings:

  MEDIA_ROOT = '/ home / user / webapps / project / uploads'' MEDIA_URL = '/ uploads /'   

and project URL:

From django.conf.urls import pattern, include, django.conf import settings from url

  from django.contrib import admin admin.autodiscover () urlpatterns = patterns ('', url ( R '^ admin /', include (admin.site.urls),) If settings.DEBUG: urlpatterns + = pattern ('', (R '^ upload / (? P & lt; path & gt ;.)) $', 'django.views.static.serve', {'document_root':   P> You should first create an image field for your model, and you should define where you want to upload your image:   " .CharField (max_length = 50) My_image = models.ImageField (blank = true, null = true, upload_to = '/ home / user / webapps / project / uploads'')   

When you want your t After getting your model object from your database in the template, try to show your image:

  & lt; Img src = "{{mymodel.my_image.url}}" alt = "{{mymodel.name}}" Width = "150" height = "200" />    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -