Wednesday, June 3, 2020

Re: Issue with serving angular with django

Hi again,

How are you serving the django application? As far as I know the only way to get django to serve your staticfiles (which you are describing) is to set DEBUG to true and also use the runserver command.

How do you get the paths to the static files? What I would do is the following:
1. Check the nginx config -  make sure that the directory that serves static files is where your STATIC_ROOT points to.
2. Check so that the STATIC_URL is correctly set - it needs to be where nginx serves the files.

These two will be automatically configured via the settings.py if you use runserver in production.... Which you definitely shouldn't :)

Regards,

Andréas


Den tis 2 juni 2020 kl 17:13 skrev Sunday Iyanu Ajayi <sunnexajayi@gmail.com>:
Hi  Andréas  , 

It actually followed the digital oceans setup in setting up the nginx server
AJAYI Sunday 
(+234) 806 771 5394



On Mon, Jun 1, 2020 at 6:24 PM Andréas Kühne <andreas.kuhne@hypercode.se> wrote:
Hi Sunday,

No - you don't. What collectstatic does is it collects all of the static files to the path where they should be stored. This should be a directory that should be served from nginx or apache or any other webserver. When you run manage.py runserver - you run a development server that isn't geared for production. And that is what is serving the files when "DEBUG" is set to True. 

To make it work like you want it to:
1. Install a webserver that can serve the static files.
2. Install gunicorn, uwsgi or some other wsgi server to serve the django application.

When you have that working you will be able to look at your custom error pages and so on. 

There are many good tutorials on howto set this up - I usually look at digitalocean - check here for example:

You can also look at the official django docs for explaining how to run production loads:

When you get this working - serving the static files from a webserver isn't that hard.

Regards,

Andréas


Den mån 1 juni 2020 kl 16:18 skrev Sunday Iyanu Ajayi <sunnexajayi@gmail.com>:
Hi Kasper,

Thanks for the response.
I serve my static file by running python manage.py collectstatic on the built file I get from the frontend angular guy 
AJAYI Sunday 
(+234) 806 771 5394



On Mon, Jun 1, 2020 at 2:55 PM Kasper Laudrup <laudrup@stacktrace.dk> wrote:
Hi Sunday,

On 01/06/2020 15.48, Sunday Iyanu Ajayi wrote:
>
> Please What am I doing wrong? Or are there better ways of serving
> angular build files on django?
>

You haven't described how you are currently serving static files with
Django. I suggest you start by reading this:

https://docs.djangoproject.com/en/3.0/howto/static-files/deployment/

You definitely shouldn't use DEBUG in production and you definitely
should serve static files with your web server of choice.

Kind regards,

Kasper Laudrup

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/12912d74-160c-547a-5cb5-0275432e751d%40stacktrace.dk.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKYSAw3vLNZ5RDLav-WuUO1kH4rn%3DF%3DcDLFdteK%2BM_4d9rR9HA%40mail.gmail.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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCcqMsfK_5Gwd9GkBHTTgR5EQKr9Vmp%3DUaZqt8WuRVCRqQ%40mail.gmail.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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKYSAw1syOBNWckifJ4dV3s9g%3DbqBJ8JfE%3DSUEArufE%2B8jyxuA%40mail.gmail.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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCdcSsgHGkvCj70xTsO-43XNvYG0RU%3DA-DftB-PbprbHyw%40mail.gmail.com.

No comments:

Post a Comment