Hello @kartik,
1) The first thing we should do with our newly created project files is adjust the settings. Open the settings file with your text editor:
gedit myproject/settings.py
At the bottom of the file, we will add a line to configure this directory. Django uses the STATIC_ROOT setting to determine the directory where these files should go. We'll use a bit of Python to tell it to use a directory called "static" in our project's main directory:
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
2) We can collect all of the static content into the directory location we configured by typing:
./manage.py collectstatic
You will have to confirm the operation. The static files will be placed in a directory called static within your project directory.
3)You need mod-wsgi adapter to configure Django in Apache install wsgi lib like below.
sudo apt-get install libapache2-mod-wsgi sudo a2enmod wsgi
4)At the bottom of file, /etc/apache2/sites-available/000-default.conf
WSGIPythonPath /var/www/html/myproject/
WSGIProcessGroup myproject
WSGIScriptAlias / /var/www/html/myproject/myproject/wsgi.py
Alias /static /var/www/html/myproject/static/
<Directory /var/www/html/myproject/static>
Require all granted
</Directory>
<Directory /var/www/html/myproject/myproject>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
Alias /media/ /var/www/html/myproject/media/
<Directory /var/www/html/myproject/media>
Require all granted
</Directory>
WSGIDaemonProcess myproject python-path=/var/www/html/myproject/
5)Restart the apache2 server:
sudo service apache2 restart
6)Now go to Localhost:
Hope it works!!
Thank You!