skip to Main Content

I have a django page where I am trying to add a banner images which is stored in a network drive.

In Dev environment:

setting.py :

MEDIA_URL = ‘/media/’

MEDIA_ROOT = PureWindowsPath(‘//shared drive/folder/’).drive

urls.py:

urlpatterns = [

path('admin/', admin.site.urls),
......
......

]

urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

models.py:

class WelcomePage(models.Model):
departmentname = models.CharField(max_length=100,blank=True,null=True)
bannerimage = models.ImageField(upload_to=’DjangoPortal/welcome/images/’,blank=True)

home.html:

        <div class="card border-secondary mb-3">
            <div class="card-body" style="padding: 0px !important;">
                <img src="{{ pagedata.bannerimage.url }}" width="100%" />
            </div>
        </div>

with the above settings the page works perfectly

In Production:

All the above settings remains the same. In settings.py DEBUG =False and ALLOWED_HOSTS=[prod server ip, localhost]

In httpd.conf I added below

Define MEDIAROOT "//shared drive/folder/"

Alias /media "${MEDIAROOT}"

<Directory "${MEDIAROOT}">

Require all granted

</Directory>

but the image is not loading.
I am getting below error on Apache restart

**
AH00526: Syntax error on line 562 of C:/Apache24/conf/httpd.conf:
<Directory ‘//shared drive/folder/’> path is invalid.**

Am I doing anything wrong?

The technology specification is Windows Server 2012 R2 + Python 3.9 + Django 3.0.1 + SQL Server+ Apachelounge 2.4

Please guide if you have worked on or aware of this kind of scenario.

2

Answers


  1. Chosen as BEST ANSWER

    I managed to sort out the issue.

    The issue was with the httpd.conf file

    In httpd.conf the settings had to be changed to

    Alias /media/ //shared drive/folder/

    <Directory //shared drive/folder> - without " marks

    Require all granted

    </Directory>

    and the apache service had to be started by a specific user without admin rights and having access to the share drive

    Rest all the settings remain as mentioned above


  2. Keep the same settings in production like you did in you environnement dev.

    MEDIA_ROOT = PureWindowsPath(‘//shared drive/folder/’).drive

    It should works.

    have a good day

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search