0

我将组合框变成了一个用 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)

网址.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)

问候!

4

1 回答 1

0

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

于 2014-06-02T22:51:21.620 回答