Re: Django Uploaded images not displayed in production

2020-06-22 Thread MUGOYA DIHFAHSIH
thanks Anton, i will also give nginx a try but currently the client has a
domain with namecheap with shared host plan and that is where he wants me
to deploy the application but name cheap has apache web server


On Sun, 21 Jun 2020 at 22:10, Anton Nyagolov  wrote:

> So guys I have found the problem. My Nginx server was only serving static
> files but not media ones, I have probably forgot about it.
> My Nginx settings were:
> The only thing I had to do is add a location for the media folder:
>
>
> @MUGOYA DIHFAHSIH
> At the begging of setting the server I also used apache2, it was pain in
> the ass and I switched to Nguix and Gunicorn. Setting the server over
> apache took me like 60-70 steps. With Nguix and Gunicorn it takes only 20
> steps, for 15 min you are all set up.
> Watch this video and follow the guy: How to Deploy Python-Django serveer
> in 20 min 
>
> --
> 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/343c056c-cd83-4ce2-a898-ecf21ef0165fo%40googlegroups.com
> 
> .
>

-- 
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/CAP%3DJD9xJXWuZVN%2Bpwk9pJJefPp%3DOuyqRCzfFCa%3DOEksb5CqvpA%40mail.gmail.com.


Re: Django Uploaded images not displayed in production

2020-06-21 Thread Anton Nyagolov
So guys I have found the problem. My Nginx server was only serving static 
files but not media ones, I have probably forgot about it. 
My Nginx settings were: 
The only thing I had to do is add a location for the media folder:


@MUGOYA DIHFAHSIH
At the begging of setting the server I also used apache2, it was pain in 
the ass and I switched to Nguix and Gunicorn. Setting the server over 
apache took me like 60-70 steps. With Nguix and Gunicorn it takes only 20 
steps, for 15 min you are all set up.
Watch this video and follow the guy: How to Deploy Python-Django serveer in 
20 min 

-- 
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/343c056c-cd83-4ce2-a898-ecf21ef0165fo%40googlegroups.com.


Re: Django Uploaded images not displayed in production

2020-06-21 Thread MUGOYA DIHFAHSIH
Actually me too i have the same problem, i have deployed django web app on
a shared host with apache linux server, and am stuck on how to serve media
files, static files like js, css, and static images not from database load
well.

But the problem is that when i submit a form that has an imagefield with
it, it throws an error message, "404" page not found.
If anyone can help me please.

On Sun, Jun 21, 2020, 21:23 Vishesh Mangla 
wrote:

> If the issue is managing static files on the server simply installing
> Django-heroku saved me from all that trouble.
>
>
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
> Windows 10
>
>
>
> *From: *Rob Riedlinger 
> *Sent: *21 June 2020 23:40
> *To: *Django users 
> *Subject: *Re: Django Uploaded images not displayed in production
>
>
>
> Check out this video  https://youtu.be/kBwhtEIXGII  Denis talks about why
> this happens
>
> On Sunday, June 21, 2020 at 7:15:43 PM UTC+2, Anton Nyagolov wrote:
>
> Thanks I will check out the group too for future reference and etc. Those
> images are uploaded to a database and are part of a model. I iterate
> through all the object and for each object I print some information
> including the images, therefore I cannot specify only one specific image. I
> use admin so I can add my (new future) projects and only by admin they
> should be able to display automatically on my website with all the
> information and structure required.
>
> Do you sugest changing the value of the imageField
> (upload_to="static//my_desired_path) ?
>
> --
> 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/33d4c599-135d-45d9-abbc-978e404e4f87o%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/33d4c599-135d-45d9-abbc-978e404e4f87o%40googlegroups.com?utm_medium=email_source=footer>
> .
>
>
>
> --
> 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/A68703DE-32D6-417B-AF0F-64EACA533FE0%40hxcore.ol
> <https://groups.google.com/d/msgid/django-users/A68703DE-32D6-417B-AF0F-64EACA533FE0%40hxcore.ol?utm_medium=email_source=footer>
> .
>

-- 
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/CAP%3DJD9x7L7S9KniwHQ4etsjnCOfj70AizbZO-1z5WxqCbLpnsg%40mail.gmail.com.


RE: Django Uploaded images not displayed in production

2020-06-21 Thread Vishesh Mangla
If the issue is managing static files on the server simply installing Django-heroku saved me from all that trouble. Sent from Mail for Windows 10 From: Rob RiedlingerSent: 21 June 2020 23:40To: Django usersSubject: Re: Django Uploaded images not displayed in production Check out this video  https://youtu.be/kBwhtEIXGII  Denis talks about why this happensOn Sunday, June 21, 2020 at 7:15:43 PM UTC+2, Anton Nyagolov wrote:Thanks I will check out the group too for future reference and etc. Those images are uploaded to a database and are part of a model. I iterate through all the object and for each object I print some information including the images, therefore I cannot specify only one specific image. I use admin so I can add my (new future) projects and only by admin they should be able to display automatically on my website with all the information and structure required. Do you sugest changing the value of the imageField (upload_to="static//my_desired_path) ? -- 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/33d4c599-135d-45d9-abbc-978e404e4f87o%40googlegroups.com. 



-- 
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/A68703DE-32D6-417B-AF0F-64EACA533FE0%40hxcore.ol.


Re: Django Uploaded images not displayed in production

2020-06-21 Thread Rob Riedlinger
Check out this video  https://youtu.be/kBwhtEIXGII  Denis talks about why 
this happens

On Sunday, June 21, 2020 at 7:15:43 PM UTC+2, Anton Nyagolov wrote:
>
> Thanks I will check out the group too for future reference and etc. Those 
> images are uploaded to a database and are part of a model. I iterate 
> through all the object and for each object I print some information 
> including the images, therefore I cannot specify only one specific image. I 
> use admin so I can add my (new future) projects and only by admin they 
> should be able to display automatically on my website with all the 
> information and structure required. 
> Do you sugest changing the value of the imageField 
> (upload_to="static//my_desired_path) ? 
>

-- 
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/33d4c599-135d-45d9-abbc-978e404e4f87o%40googlegroups.com.


RE: Django Uploaded images not displayed in production

2020-06-21 Thread Vishesh Mangla
Sorry, I misunderstood your problem. But can you also show your views.py. Also your path to MEDIA_ROOT is obfuscated. I used MEDIA_ROOT = os.path.join(BASE_DIR, 'media'). I thing this shall be sufficient to do for a try.  Sent from Mail for Windows 10 From: Anton NyagolovSent: 21 June 2020 22:46To: Django usersSubject: Re: Django Uploaded images not displayed in production Thanks I will check out the group too for future reference and etc. Those images are uploaded to a database and are part of a model. I iterate through all the object and for each object I print some information including the images, therefore I cannot specify only one specific image. I use admin so I can add my (new future) projects and only by admin they should be able to display automatically on my website with all the information and structure required. Do you sugest changing the value of the imageField (upload_to="static//my_desired_path) ? -- 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/d4758123-f506-401b-b488-c3f17385d9fco%40googlegroups.com. 



-- 
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/C64216E4-101F-4398-8264-9499B18F82C2%40hxcore.ol.


Re: Django Uploaded images not displayed in production

2020-06-21 Thread Anton Nyagolov
Thanks I will check out the group too for future reference and etc. Those 
images are uploaded to a database and are part of a model. I iterate 
through all the object and for each object I print some information 
including the images, therefore I cannot specify only one specific image. I 
use admin so I can add my (new future) projects and only by admin they 
should be able to display automatically on my website with all the 
information and structure required. 
Do you sugest changing the value of the imageField 
(upload_to="static//my_desired_path) ? 

-- 
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/d4758123-f506-401b-b488-c3f17385d9fco%40googlegroups.com.


RE: Django Uploaded images not displayed in production

2020-06-21 Thread Vishesh Mangla
Hi, first of all welcome on this group. Secondly you can also try https://webchat.freenode.net/  on the #django channel but you first need to register there by asking on #freenode channel. Regarding your problem, images are static files and you should put them in static//your_desired_path to be detectable not media if they are part of your templates. Use src="" url “your_desired_path %} and don’t forget to put {% load static %} at the top of your template. Sent from Mail for Windows 10 From: Anton NyagolovSent: 21 June 2020 22:29To: Django usersSubject: Django Uploaded images not displayed in production Hello everyone, I just discovered this group through Google.I couldn't get any help on stack overflow and hopefully someone here can help. I have deployed a Django App on a Ubuntu server for the first time using Nginx and gunicorn. Before deployment, I used port 8000 to test if everything runs as it is supposed to and all was fine. Since I allowed 'Nginx Full' my database images are not showing up. This is my django project structure:My virtual environment folder and my main project folder are both in the same directory. I have separated them. ```python# Create your models here.class Project(models.Model):    project_name = models.CharField(max_length=120)    project_description = models.CharField(max_length=400)    project_link = models.CharField(max_length=500)    project_image = models.ImageField(upload_to='')    def __str__(self):    return self.project_name``` I have set up my settings.py to :```python# Build paths inside the project like this: os.path.join(BASE_DIR, ...)BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))STATIC_URL = '/static/'STATIC_ROOT = os.path.join(BASE_DIR, 'static')MEDIA_URL = '/media/'MEDIA_ROOT = os.path.join(os.path.dirname(__file__), '..', 'media').replace('\\','/')```My view gets all the project object from a database and passes those to the template. The template renders successfully all other information related to project model except the image field . In my template I do: ```html  {% for project in projects %}    {% if forloop.counter|mod:2 == 0 %}      {% else %}      {% endif %}      alt="Image could not be found :(" style="height:120px; width:166px !important;" />      {{ project.project_name }}  {{ project.project_description}}  Link        {% if forloop.counter|mod:2 == 0 %}    {% endif %}  {% endfor%}      ```Uploading the images works, it sends them in the project's media directory, the problem is that they are not showing up, the alt="" is activated. My main urls.py: ```pythonurlpatterns = [ path('', include('project.urls')),    path('admin/', admin.site.urls),]  + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)```The gunicorn system file:```[Unit]Description=gunicorn daemonAfter=network.target[Service]User=myusernameGroup=www-dataWorkingDirectory=/home/myusername/myprojectExecStart=/home/myusername/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/myusername/myproject/myproject.sock myproject.wsgi:application[Install]WantedBy=multi-user.target```Nginx setup:```  server {    listen 80;    server_name  ;    location = /favicon.ico { access_log off; log_not_found off; }    location /static/ {    root /home/myusername/myproject;    }    location / {    include proxy_params;    proxy_pass http://unix:/home/myusername/myproject/myproject.sock;    }    }```EDIT: When inspecting the image element of the webpage the source of the image it is "/media/imageNmae.png". Any help would be appreciated!-- 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/635fcf7e-6e53-425d-aad1-8638fef425c1o%40googlegroups.com. 



-- 
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/CCDBA280-8772-4A69-9698-430CB19A687A%40hxcore.ol.