代码之家  ›  专栏  ›  技术社区  ›  anonymous coward

使用URL前缀(“子目录”)运行Django-应用程序可以工作,但URL损坏了?

  •  12
  • anonymous coward  · 技术社区  · 16 年前

    http://dpaste.com/97213/ .

    我想在前缀'/d'处为Django/应用程序提供服务,因此'example.com/d/'将加载默认应用程序,'example.com/d/app3'将加载另一个应用程序,如urls.py中配置的那样。

    我是 这里做错了,或者这是Django在生成url时的一个bug。

    编辑: 应用程序、评论和登录都运行良好。即使转到“example.com/admin”也会加载管理员,尽管我让管理员媒体坏了,所以没有加载样式表。

    #
    # /home/blah/django_projects/Ticket/urls.py
    #
    from django.conf.urls.defaults import *
    from django.contrib import admin
    admin.autodiscover()
    
    urlpatterns = patterns('',
        (r'^', include('ticket.urls')),
        (r'^admin/', include(admin.site.urls)),
        (r'^comments/', include('django.contrib.comments.urls')),
    )
    
    
    #
    # /home/blah/django_projects/Ticket/apache/django.wsgi
    #
    import os, sys
    
    sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
    
    sys.path.append('/home/blah/django_projects')
    sys.path.append('/home/blah/django_projects/Tickets')
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'Tickets.settings'
    
    import django.core.handlers.wsgi
    
    application = django.core.handlers.wsgi.WSGIHandler()
    
    
    #
    # /etc/apache2/sites-available/django_tickets_wsgi (apache conf)
    #
    NameVirtualHost *
    <VirtualHost *>  
    
        Alias /media /home/blah/django_projects/Tickets/media
    
    
        WSGIScriptAlias /d /home/blah/django_projects/Tickets/apache/django.wsgi
        WSGIDaemonProcess exmaple_com user=blah group=blah processes=1 threads=10
        WSGIProcessGroup example_com
    
        ServerAdmin localhost@example.com
        ServerName example.com
    
        DocumentRoot /var/www/
    
        <Directory /var/www/>
            Options -Indexes FollowSymLinks -MultiViews -Includes 
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>
    
        ErrorLog /var/log/apache2/error.log
    
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
    
        CustomLog /var/log/apache2/access.log combined
        ServerSignature Off
    
    </VirtualHost>
    
    2 回复  |  直到 16 年前
        1
  •  7
  •   Community Mohan Dere    9 年前

    Django Apache Redirect Problem .

    alex vasi )

    1. 看起来你的网站正在使用login_required装饰器。在这种情况下,您可以添加到settings.py:

      /帐户/登录/'

        2
  •  2
  •   antyrat Andy    14 年前

    urlpatterns = patterns('',
        '^', include(base_urlpatterns), # iff you wish to maintain the un-prefixed URL's too
        '^your_prefix/', include(base_urlpatterns),
    )