Mirco
i did the same things but it says "STATICFILES_DIRS setting should not contain the STATIC_ROOT setting. "
Put your static folders insider the first one STATIC_ROOT is the folder where Django will put all static things after running collect static command
Mirco
i tried everything.. :(
Have u already ran manage.py collectstatic ?
ibrahim süren
yep
ibrahim süren
i did the same what docs say
Mirco
Have u checked if your STATIC_ROOT has all dirs after running collect static ?
Mirco
In your urls.py , add static() if your settings.DEBUG is True
ibrahim süren
debug is False
ibrahim süren
i have already added static url
Mirco
Yep but you need to serve with static() app only when debug is True
Mirco
if settings.DEBUG is True: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Mirco
Nope
ibrahim süren
removed, doesn't makes sense :(
Mirco
When debug is False, Django will look for statics inside your static root When debug is True, it uses static app If u see default apps in your settings, you should see something like django.contrib.staticfiles
ibrahim süren
yes
Mirco
So, put all your URLs in your urlpattern as usual Then if debug is True serve static with default static app otherwise Django will point to your static root
ibrahim süren
when i serve with debug= True
ibrahim süren
it shows css files, no problem
ibrahim süren
but when make it False, not works
Mirco
Try to put the code I suggested you
Mirco
I understood what you mean It's normal, when your debug is True Django uses its default static app
Mirco
After your urlpatterns definition
ibrahim süren
my server has only postgresql and django. Is it needs apache?
Mirco
Nope
George
apache is another world
Mirco
Exactly
George
apache is your django for php xD
Mirco
😂😂
George
i like to talk about what people should know
ibrahim süren
This one
but i will work only on DEBUG= True
Mirco
but i will work only on DEBUG= True
Put the code I suggested you then try with DEBUG True and False and you will understand
Mirco
Tell Django to use its default static app only for dev scenario , otherwise look for statics inside static root
ibrahim süren
Put the code I suggested you then try with DEBUG True and False and you will understand
tried, when i start with DEBUG = True, no problem when Debug = False, no css
Mendel
but i will work only on DEBUG= True
Did you define STATIC_ROOT and run collectstatic?
ibrahim süren
yes
Mirco
Ok, use pastebin to share your settings and urls.py
Mirco
We could understand and read better
Mendel
We could understand and read better
Bro do you mind taking a look at what I posted in other group? 🙏
ibrahim süren
https://paste.ofcode.org/QVKw5kR9TaFS5j9dAcvWYb settings https://paste.ofcode.org/Z34juWdqK56wmTadVjAGXS urls
Mirco
Thanks 😀
Mendel
Which one ?
Django Italia
Mirco
Django Italia
Oh yeah, I was reading it this morning
Mirco
https://paste.ofcode.org/QVKw5kR9TaFS5j9dAcvWYb settings https://paste.ofcode.org/Z34juWdqK56wmTadVjAGXS urls
Another thing to check is with your browser console, into the network section Read which url it shows in red for static files
ibrahim süren
<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css" /> <link rel="stylesheet" type="text/css" href="/static/admin/css/login.css" />
Mirco
Mmm are you sure this is from network section ? And not element one ?
Mirco
If I'm not going wrong, try to right click on one of them and go to new tab You should see the exact uri
Mirco
Django Italia
Try to run nginx -t without specifying conf file
Mendel
Try to run nginx -t without specifying conf file
mendel@bootanmts-server:/etc/nginx/sites-available$ nginx -t nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2018/12/16 14:11:28 [warn] 5200#5200: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1 2018/12/16 14:11:28 [emerg] 5200#5200: open() "/etc/nginx/sites-enabled/django_server_nginx.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62 nginx: configuration file /etc/nginx/nginx.conf test failed mendel@bootanmts-server:/etc/nginx/sites-available$ sudo nginx -t nginx: [emerg] open() "/etc/nginx/sites-enabled/django_server_nginx.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62 nginx: configuration file /etc/nginx/nginx.conf test failed
Mendel
Try to run nginx -t without specifying conf file
i think i linked it wrong, look at this tutorial
Mendel
https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
Mendel
it says to create mysite_nginx.conf in /etc/nginx/sites-available, then says to link it from path/to /mysite (which would be /home/mendel/django_server)
Mendel
so now i linked from sites-available to sites-enabled, and now gives this error: mendel@bootanmts-server:/etc/nginx/sites-available$ sudo nginx -t nginx: [emerg] open() "/etc/nginx/sites-enabled/django_server_nginx.conf" failed (40: Too many levels of symbolic links) in /etc/nginx/nginx.conf:62 nginx: configuration file /etc/nginx/nginx.conf test failed
ibrahim süren
am i need uwsgi or nginx?
Mendel
ok @iFlare3G , i linked now correctly and now it doesn't give errors, tho media serving still doesn't work
Rajjix
same process as static, specify media_root directory and link to nginx just as you did with static_root
Mirco
am i need uwsgi or nginx?
Nope, Django is enough I think there's something stupid we cannot see 😓
Mendel
# server unix:///path/to/your/mysite/mysite.sock; do i need to put unix:///? or just one slash?
Mirco
If I well remember, there are 3 But it's Sunday and my memory could be bad 😂 check docs to be sure
Mirco
Set view permissions
R
I need to have a simple search form of just one field which uses autocomplete, creating this is not a problem, but I want to have this form in the sidebar menu which is located in my base template, so the form should be in all of my templates. The thing is, I don’t know which approach to follow, some idea would be creating a Mixin that adds the form in all my views context or maybe a template tag, any suggestion of which approach to follow or any better approach I’ve not thought with?
R
That’s why was considering the Mixin option
R
Maybe a good choice would be a custom context processor
Mirco
check on official docs , you can find all you need
ibrahim süren
Comment out STATIC_ROOT
gives error when do like that
Ghorz
Your settings should have both static URL and static root
Ghorz
During development, collectstatic
Ghorz
On deployment, comment out static root
Ghorz
Debug True
Ghorz
Allowed host '*'