简体   繁体   中英

Django with Apache working for admin page but gives 404 for all other urls

I am a django beginner.

I tried to deploy my django(1.10) site from local server using apache2 (2.4.7) Port opened.

Admin page is getting opened properly but all other views are not getting opened.

URLS.PY

from django.conf.urls import url,include
from django.contrib import admin
from django.views.generic import RedirectView
from django.conf import settings
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^treedump/',include('treedump.urls')),
    url(r'^$', RedirectView.as_view(url='/treedump/', permanent=True)),
    url(r'^accounts/', include('django.contrib.auth.urls')),
 ]

TREEDUMP.URLS

from django.conf.urls import url

from . import views

urlpatterns=[
    url(r'^$',views.index,name='index'),
    url(r'printx$',views.printx,name = 'printx'),
    url(r'download$',views.download,name = 'download'),

    ]

.CONF FILE IN APACHE

 <VirtualHost *:80>
     ServerName *********
     DocumentRoot /var/www/html/

  Alias /static /data1/ekmmsc/webapp/ekmmsc/static

  WSGIDaemonProcess ekmmsc python-path=/data1/ekmmsc/webapp/ekmmsc python-     home=/data1/ekmmsc/webapp/ekmmsc/ekmmscenv
  WSGIProcessGroup ekmmsc
  WSGIScriptAlias /ekmmsc /data1/ekmmsc/webapp/ekmmsc/ekmmsc/wsgi.py

  # Other directives here ...
  <Directory "/var/www/html/">
    allow from all
    order allow,deny
    AllowOverride All
    AddType text/css .css
    AddType text/javascript .js
  </Directory>


  <Directory "/data1/ekmmsc/webapp/ekmmsc/static">
    Require all granted
  </Directory>

  <Directory "/data1/ekmmsc/webapp/ekmmsc/ekmmsc">
    <Files wsgi.py>
       Require all granted
    </Files>
  </Directory>



  </VirtualHost>

OUTPUT

Not Found

The requested URL /treedump/ was not found on this server.

Any help will be appreciated , i have been working almost for 2 days on this. Please help.

You should use pattern_name rather than url in your view. This will make Django look up the URL by name, rather than using a hard-coded value, so it will take into account the script prefix.

RedirectView.as_view(pattern_name='index', permanent=True)),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM