模板中的可选参数在没有参数时导致错误

时间:2016-05-28 13:20:13

标签: python django

这是我的urls.py

 SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ESCProjectProgStatusController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.interland.b2b.service.ESCProjectProgStatusService com.interland.b2b.controller.ESCProjectProgStatusController.escProjectProgStatusService; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'com.interland.b2b.service.ESCProjectProgStatusService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.interland.b2b.service.ESCProjectProgStatusService]: no matching editors or conversion strategy found
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1208)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:759)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.interland.b2b.service.ESCProjectProgStatusService com.interland.b2b.controller.ESCProjectProgStatusController.escProjectProgStatusService; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'com.interland.b2b.service.ESCProjectProgStatusService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.interland.b2b.service.ESCProjectProgStatusService]: no matching editors or conversion strategy found
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
        ... 22 more
    Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String' to required type 'com.interland.b2b.service.ESCProjectProgStatusService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.interland.b2b.service.ESCProjectProgStatusService]: no matching editors or conversion strategy found
        at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:74)
        at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:54)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:961)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
        ... 24 more
    Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.interland.b2b.service.ESCProjectProgStatusService]: no matching editors or conversion strategy found
        at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:287)
        at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:124)
        at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:61)
        ... 28 more

我有一个名为urlpatterns = [ url(r'^bankcreate/(?:(?P<info_id>[1-9]+)/)?$' , views.bankcreate , name='account-bankcreate'), ] 的url,带有一个可选参数...基本上如果传递一个参数来查看它的编辑/更新操作,如果不是它的插入操作

我的观点就像这样开始

account-bankcreate

它工作正常但在模板中我试图设置表单操作

def bankcreate( requset , info_id = 0 ):
    errors = []
    default = None
    if info_id is not None and int(info_id) > 0 :
        try:
            default = BankAccounts.objects.get(id=info_id , user_id=requset.user.id)
        except BankAccounts.DoesNotExist :
            default = None

如果没有参数传递给视图我得到这个错误(当有参数时它可以正常工作):

 <form method="post" action="{%  url 'account-bankcreate' default.id %}">

此链接正常

NoReverseMatch at /account/bankcreate/

Reverse for 'account-bankcreate' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['account/bankcreate/(?:(?P<info_id>[1-9]+)/)?$']

Request Method:     GET
Request URL:    http://localhost:8000/account/bankcreate/
Django Version:     1.9.6
Exception Type:     NoReverseMatch
Exception Value:    

Reverse for 'account-bankcreate' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['account/bankcreate/(?:(?P<info_id>[1-9]+)/)?$']
Error during template rendering

In template C:\wamp\www\django\paypal\account\templates\account\bankcreate.html, error at line 5
Reverse for 'account-bankcreate' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['account/bankcreate/(?:(?P<info_id>[1-9]+)/)?$']
1   {%  extends 'master-account.html' %}
2   
3   {%  block main %}
4   <div class="col-md-7 col-md-offset-2">
5       <form method="post" action="{%  url 'account-bankcreate' default.id %}">
6           {%  csrf_token %}
7   
8   
9           {% if errors %}
10            <div class="alert alert-danger">
11            <ul>
12            {%  for e in errors %}
13             <li>  {{ e }} </li>
14            {%  endfor %}
15            </div>

这是堂兄错误

http://localhost:8000/account/bankcreate/1/

0 个答案:

没有答案