0

I'm working on Django 1.11, the URL,

http://djangoserver:8002/dj/dev/userlogin/789

works with development server, but with apache URL:

http://djangoserver/dj/dev/userlogin/789

it throws Page not found (404) error.

Regex used for the URL is : url(r'^[0-9]+$', views.userlogin.login , name='login'),

The reset of pages are displayed properly.

I have tried solution posted in the following posts which did not work for me: django application works on development server but I get 404 on Apache

working on django development server but not on apache

django production server: root path

I'm not using any virtualhost.My httpd.conf file code snippet:

WSGIScriptAlias /dj /var/www/html/dev/dev/wsgi.py

WSGIDaemonProcess djangoserver  python-path=/var/www/html/dev

WSGIProcessGroup djangoserver

WSGIScriptAlias /dj /var/www/html/dev/dev/wsgi.py process-group=djangoserver

<Directory /var/www/html/dev/dev >
#       Options -Indexes +SymLinksIfOwnerMatch
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /var/www/html/dev/dev_app/static/
<Directory /var/www/html/dev/dev_app/static/ >
    Require all granted
</Directory>
2
  • Could be usefull if you post here your Apache Configuration file (at least, the VirtualHost file you are using) Commented Dec 29, 2017 at 8:46
  • @jeasoft I have added the code snippet Commented Dec 29, 2017 at 8:59

2 Answers 2

2

You're setting /dj as the the alias for your Django application, that means your Django app receives the path /dev/userlogin/789, not /dj/dev/userlogin/789. On your dev server that's the path that works, so you should change your Apache configuration to:

WSGIScriptAlias / /var/www/html/dev/dev/wsgi.py

So that /dj is still part of the path parsed by your application.

Sign up to request clarification or add additional context in comments.

6 Comments

I have tried this solution, it does not work. With out any alias, django throws 404 error. Even if url file states : url(r'^dev/', include('dev_app.urls',namespace='dev_app',app_name='dev_app')), url(r'^dj/dev/', include('dev_app.urls',namespace='dev_app',app_name='dev_app')),
Do you know if the 404 is thrown by Apache or Django? Check your logs.
Would help then to show us the error, what URL is it trying to match?
The error thrown is: Using the URLconf defined in dev.urls, Django tried these URL patterns, in this order: ^admin/ ^dev/ ^dj/dev/ The empty path didn't match any of these.
that's when trying to fetch /dj/dev/userlogin/789? The error says django received an empty path... Note also that your WSGIScriptAlias should be at the end (if using /) in order to catch the static alias.
|
0

The only change I made is to declare WSGIScriptAlias along with process-group in httpd.conf file, code snippet:

WSGIDaemonProcess djangoserver  python-path=/var/www/html/dev

WSGIProcessGroup djangoserver

WSGIScriptAlias /dj /var/www/html/dev/dev/wsgi.py process-group=djangoserver

<Directory /var/www/html/dev/dev >
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /var/www/html/dev/dev_app/static/
<Directory /var/www/html/dev/dev_app/static/ >
    Require all granted
</Directory>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.