【问题标题】:404 when call Dajaxice function cause of WSGI Alias调用 WSGI Alias 的 Dajaxice 函数时出现 404
【发布时间】:2014-07-23 01:51:39
【问题描述】:

我有组合框到一个用 Dajaxice 动态刷新的表单中,我在开发中没有问题,但是在使用 WSGI 的生产中我有以下问题:

项目的VirtualHost 有一个别名WSGIScriptAlias /dgp /path/to/wsgi 用于加载Web 应用程序,所有路由都在此子站点下构建,但Dajaxice 没有,其中url 必须是http://example.com/dgp/dajaxice/ventas.updatecomboproducto/ 而我们有http://example.com/dajaxice/ventas.updatecomboproducto/ 显然可以'找不到任何东西,所以我不知道如何告诉 Dajaxice 注意到 wsgi 别名,我尝试使用 DAJAXICE_MEDIA_PREFIX='dgp' 但这仅适用于子站点,也就是说,仅适用于 http://desarrollorivas.no-ip.org/dgp/dgp/dajaxice/ventas.updatecomboproducto/,这无法解决任何问题。

有什么想法吗?这就是代码,categoria 是我调用 Dajaxice 进程并加载 url 的地方:

class DetallePedidoModelForm(forms.ModelForm):
    id = forms.IntegerField(widget=forms.HiddenInput)
    categoria = forms.ChoiceField(choices=[[0, '----------']] + [[c.id, c.nombre] for c  in Categoria.objects.all()],widget=forms.Select(
        attrs={'onchange': 'Dajaxice.ventas.updatecomboproducto(Dajax.process, {"option":this.value,"id":this.id});'}))
    #producto = forms.ChoiceField(choices=[[0, '----------']] + [[p.id, p.nombre] for p  in Producto.objects.all()],widget=forms.Select(
        #attrs={'onchange': 'Dajaxice.ventas.updatevaluecantidadproducto(Dajax.process, {"option":this.value,"id_producto":this.id});'}))
    cantidad = forms.IntegerField(widget=NumberInput(attrs={'min':'0','step':'1','style':'width: 50px;','value':'0'}))
    descuento =  forms.FloatField(widget=NumberInput(attrs={'step':'any','style':'width: 50px;','value':'0.0'}))
    pvp_manipulacion =  forms.FloatField(widget=NumberInput(attrs={'step':'any','value':'0.0'}))
    class Meta:
        model = Detalle_Pedido
        fields = ["id","categoria","producto","unidad_precio","cantidad","descuento","manipulacion","pvp_manipulacion"]

    def __init__(self,*args,**kwargs):
        super(DetallePedidoModelForm, self).__init__(*args,**kwargs)
        self.fields['categoria'].empty_label = "Selecciona una categoria"
        self.fields['producto'].widget.attrs["onchange"] = 'Dajaxice.ventas.updatevaluecantidadproducto(Dajax.process, {"option":this.value,"id_producto":this.id});'




PedidoForm = modelform_factory(Pedido, PedidoModelForm, exclude=("producto",),formfield_callback=make_custom_datefield)
DetallePedidoFormSet = modelformset_factory(Detalle_Pedido,exclude=("unidad_precio","pedido",),
                                            form=DetallePedidoModelForm)

urls.py

 from django.conf.urls import patterns, include, url
 from django.conf import settings
 from django.conf.urls.static import static
 from django.contrib import admin
 from . import views
 from dajaxice.core import dajaxice_autodiscover, dajaxice_config
 dajaxice_autodiscover()

 admin.autodiscover()

 urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'dgp.views.home', name='home'),
    #url(r'^login/$', views.login,{'template_name': 'login.html'},name="my_login"),
    url(r'^login/$', 'django.contrib.auth.views.login',{'template_name': 'login.html'},name="my_login"),
    url(r'^logout/', 'django.contrib.auth.views.logout',{'template_name': 'logout.html'},name="my_logout"),
    url(r'^ventas/', include('ventas.urls', namespace="ventas")),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', include('ventas.urls')),
    url(dajaxice_config.dajaxice_url, include('dajaxice.urls')),
    )+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

问候!

【问题讨论】:

    标签: python django wsgi dajaxice dajax


    【解决方案1】:

    代码应考虑到应用程序的 URL 挂载点可能不在网站的根目录,方法是使用适当的函数来构造包含挂载点的 URL。请参阅以下位置的文档:

    【讨论】:

    • Dajaxice 怎么可能呢?我所拥有的只是一个像 url(dajaxice_config.dajaxice_url, include('dajaxice.urls')), 这样的 url 模式,其余的 url 只指向 dgp 的“根”,为什么 Dajaxice 的解释与其他的不一样?我将使用 urls.py 进行编辑,因为在这种情况下使用 reversenot 帮助你可以看到我想说的,因为我使用的是 Dajax 函数,我通过几个 args 传递进程,我想我错过了什么......
    猜你喜欢
    • 1970-01-01
    • 2017-03-06
    • 2020-06-08
    • 2014-11-29
    • 2020-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    相关资源
    最近更新 更多