What If I compile the py manage.py collectstatics? - python

What If I compile the py manage.py collectstatics? I am on my localhost. I have configured all the s3 url accourding to given url. We can see on last paragraph then it's telling run
python manage.py collectstatic .
My question is why we are doing this? Do we need to run this on every static or media changes? I tried to run this but it asking do you want to override this? Can I simply do yes? If I give yes then what will happen?
I am not much aware in this topic collectstatics

Related

Is there a way I can avoid stopping and starting 'python manage.py runserver' on Django everytime I make a change?

Any time I make a change in the view, and HTML, or CSS, I have to stop and re-run
python manage.py runserver
for my changes to be dispayed. This is very annoying because it wastes a lot of my time trying to find the terminal and run it again. Is there a workaround for this?
python manage.py runserver should normally perform hot reload on your Django application, except you've updated the config in the settings.py file. Check if DEBUG = True in settings.py
My advice is to use Vscode for Django developing because it gives you autosave feature so you don't have to stop and rerun the server the only thing you have to do is reload the web page. I hope it might be helpful

Django 'collectstatic': is it a bad practice to automate it?

I have a Django project as a webserver (Apache2) on a Linux machine.
The server needs to periodically analyze some files outside the Django project folder, so I'm running python3 manage.py collectstatic to gather all files into my static directory.
I couldn't find anything related to this, so I would like to know if is this a Bad practice or if already exist a better way to do this...
Should I add a cronjob or systemd service to execute python3 manage.py collectstatic --noinput and automate this process? Is there a better alternative?

I want to Create my first URL using the command prompt

I have Django installed,but I was trying to create my first URL and I typed the following using the command prompt
"cd myproject" then again I typed "manage.py runserver 127.0.0.1:8000" And I got the following output:
"System check identified no issues<0 silenced>
you have 17 unapplied migration. Your project may not work properly until you apply the migrations for app: admin,auth,contenttypes,sessions."
Please what do I do to fix this problem so that my project can work properly?
Note that: I am new in using Python and Django
You already have an advice to read the tutorial but in case you want to continue on your own (before next trouble), you need to run this in console in order to apply migrations:
python manage.py migrate
Read more about migrations and this command here.
You need to migrate the database first. But it's not error actually. It's just a warning. If you don't want to migrate(create DB tables) just ignore it. And you can still browse 127.0.0.1:8000
Migration command
python manage.py migrate
Read Django documentation very carefully. Django Official Documentation

How to clear code cache in python/django?

Sorry, I'm newbie on python.
I change code in .py file but no changes happens.
Guess, script code is cahced in memory.
What should I do to make my changes working?
PS: tried to delete complied .pyc file, no luck 8-(
guess, IO need to try to restart uwsgi/nginx?
Older versions of django
find . -name "*.pyc" -exec rm -rf {} \;
New version of django has this:
python manage.py clean_pyc
If you simply want to restart the webserver it depends on the configuration you are using:
via gunicorn:
use --reload option
via django inbuilt runserver:
since version 1.7 it automatically does that.
Just touch the WSGI file: touch wsgi.py and your project should refresh.
Please have a look at this similar request: How to reload new update in Django project with Apache, mod_wsgi?

How to autorun collectstatic on local django instance?

While developing locally on a side Django project, my workflow is currently this:
Make changes.
Go to Terminal session with virtual environment. Stop foreman with ctrl+C.
Type python manage.py collectstatic to move all my static css/js/img files.
Restart foreman with foreman start.
In an attempt to be more efficient and do a better job of learning, I'm wondering how I can optimize the workflow is it's more like this:
Make changes.
Run a single command that moves static files and restarts foreman.
Would someone be able to point me in the right direction. Thanks.
You could create a bash script that does this bunch of commads for you.
While I have no experience with foreman, you could create a script with content something like:
#!/bin/bash
sudo killall foreman
python manage.py collectstatic
foreman start
Then add execution rights to it:
chmod +x script.sh
And execute everything in one command:
./script.sh
I assume you absolutely can't get around using foreman for local development, cause otherwise you would not even need to do a collectstatic or manual restart.
Maybe writting a custom management command based on runserver is the way to go for you, as it would already have the check-for-change-and-restart logic in it.
https://docs.djangoproject.com/en/dev/howto/custom-management-commands/
https://github.com/django/django/blob/master/django/core/management/commands/runserver.py?source=cc

Categories