31

I am trying to run Django inside WordPress like WordPress at main url www.wptesting.com and Django at suburl www.wptesting.com/django . Django main root url Is working fine at www.wptesting.com/django but its suburl e.g., admin is not working as it should be www.wptesting.com/django/admin . However, whenever I tried to request admin url it goes converts into www.wptesting.comhttp%3a//wptesting.com/django/admin

I am running WordPress and Django with Apache and mod_wsgi , my conf file for apache is as follows :

<VirtualHost *:80>

WSGIScriptAlias /django /path_to_project/wsgi.py

ServerName wptesting.com
ServerAlias www.wptesting.com

DocumentRoot /var/www/html/wordpress

<Directory /var/www/html/wordpress/>
AllowOverride All
Order allow,deny

allow from all
#            Options Indexes FollowSymLinks
#            Require all granted
</Directory>


<Directory /path_to_project/>
            Options Indexes FollowSymLinks
            Require all granted
</Directory>


</VirtualHost>

I have asked one question earlier about configuring Django from subdirectory of WordPress with Apache and wsgi -> you can see the question here

Also If I tried to access any url which is not in Django project then it is giving the standard 404 not found error but when I try to access any valid url like admin it is giving the error mention above.

Edited : My Urls.py file :

from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import TemplateView

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'dev_redis.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^$',TemplateView.as_view(template_name='index.html')),
    url(r'^admin/', include(admin.site.urls)),

    url(r'^cache/', 'redis_app.views.redisTest'),

)
Community
  • 1
  • 1
Inforian
  • 1,716
  • 5
  • 21
  • 42
  • 1
    Just couple of questions: Did you check whether the `urls.py` is having the admin url and also auto discover for admin module? – Nagaraj Tantri Sep 25 '14 at 06:28
  • 1
    yes urls.py have admin module , even I can access that on development server – Inforian Sep 25 '14 at 07:01
  • 1
    Could you provide a small insight of what your urls.py has? Don't have to show everything, just show the admin autodiscover() – Nagaraj Tantri Sep 25 '14 at 08:29
  • 1
    I have edited my question and added urls.py file code . However its not about admin urls only , it happens with other valid urls too , I am just referring to admin url as an example. – Inforian Sep 25 '14 at 09:12
  • 6
    Possible duplicate of [How to host a Django project in a subpath?](https://stackoverflow.com/questions/28147916/how-to-host-a-django-project-in-a-subpath) – FamousJameous Jun 13 '18 at 22:10
  • maybe you need to define a dedicated proxy-pass directive to django site? – noise Feb 21 '21 at 19:06
  • I hope you are aware that both Django and apache run as backend webserver. – lewis machilika Jun 28 '21 at 13:10

2 Answers2

1

That's the old format for urls.py. The current is this:

"""monero URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from monero import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('/', views.py),
]

This is actually the file that is made when you make a new django project.

Kovy Jacob
  • 489
  • 2
  • 16
-2

Firstly, Django and apache run as backend webservers. Therefore, you can solve this by running apache and Django on two separate ports.

Then you can redirect from the current Django site to the new site using HttpResponseRedirect.

lewis machilika
  • 819
  • 2
  • 11
  • 25