Django不会在POST提交的表单上重新执行代码

时间:2015-04-07 19:57:11

标签: python django forms

我为django的奇怪行为而生气。 我在virtualenv中安装了这些软件包:

Django==1.6.10
South==1.0.2
argparse==1.2.1
dj-database-url==0.3.0
django-appconf==1.0.1
django-classy-tags==0.6.1
django-cms==3.0.12
django-compressor==1.4
django-debug-toolbar==1.3.0
django-extensions==1.5.1
django-mptt==0.6.1
django-reversion==1.8.5
django-sekizai==0.8.1
djangocms-admin-style==0.2.5
djangocms-column==1.5
djangocms-file==0.1
djangocms-flash==0.1
djangocms-googlemap==0.2
djangocms-inherit==0.1
djangocms-installer==0.7.2
djangocms-link==1.5
djangocms-picture==0.1
djangocms-style==1.5
djangocms-teaser==0.1
djangocms-text-ckeditor==2.4.3
djangocms-video==0.1
sorl-thumbnail==12.2
sqlparse==0.1.14
wsgiref==0.1.2

这些是我的INSTALLED_APPS:

INSTALLED_APPS = (
    'djangocms_admin_style',
    'djangocms_text_ckeditor',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.admin',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'django.contrib.staticfiles',
    'django.contrib.messages',
    'cms',
    'menus',
    'sekizai',
    'mptt',
    'djangocms_style',
    'djangocms_column',
    'djangocms_file',
    'djangocms_flash',
    'djangocms_googlemap',
    'djangocms_inherit',
    'djangocms_link',
    'djangocms_picture',
    'djangocms_teaser',
    'djangocms_video',
    'djangocms_img',
    'south',
    'reversion',
    'europentech',
    'compressor',
    'django_extensions',
    'sorl.thumbnail',
    'cms_sorl_pictures',
    'cmsplugin_contact',

)

我在第83行更改了文件venv / local / lib / python2.7 / site-packages / django / template / response.py:

...
    @property
    def rendered_content(self):
        """Returns the freshly rendered content for the template and context                                                                         
        described by the TemplateResponse.                                                                                                           

        This *does not* set the final content of the response. To set the                                                                            
        response content, you must either call render(), or set the                                                                                  
        content explicitly using the value of this property.                                                                                         
        """
        template = self.resolve_template(self.template_name)
        context = self.resolve_context(self.context_data)
        content = template.render(context)
        import ipdb; ipdb.set_trace()                                                                                                               
        return content
...

我启动服务器:

python manage.py runserver 0.0.0.0:8000
Validating models...

0 errors found
April 06, 2015 - 20:40:57
Django version 1.6.10, using settings 'mysite.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

然后我打开URL / en-gb / where是cmsplugin_contact的形式:

venv/local/lib/python2.7/site-packages/cms/plugin_base.py:153: DeprecationWarning: CMSPlugin.render_template attribute is deprecated and it will be removed in version 3.2; please movetemplate in plugin classes
  'template in plugin classes', DeprecationWarning)

> venv/local/lib/python2.7/site-packages/django/template/response.py(84)rendered_content()
     83         import ipdb; ipdb.set_trace()
---> 84         return content
     85

ipdb>

然后我按'c':

> venv/local/lib/python2.7/site-packages/django/template/response.py(84)rendered_content()
     83         import ipdb; ipdb.set_trace()
---> 84         return content
     85

ipdb> c
[06/Apr/2015 20:48:43] "GET /en-gb/ HTTP/1.1" 200 8802
[06/Apr/2015 20:48:43] "GET /static/js/init.js HTTP/1.1" 304 0
[06/Apr/2015 20:48:44] "GET /media/cache/69/81/69812df34b543e84695d2fb81254ae7a.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:48:44] "GET /media/cache/dc/1f/dc1fb825d31a93fa3842e6009768bbd7.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:48:44] "GET /media/cache/44/0b/440b37e962da20f9be431bedbea6b396.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:48:44] "GET /media/cache/69/3e/693e37fb3f53f61edfe1bec9d4e22d2b.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:48:44] "GET /media/cache/e8/25/e825db20363a63ae012c2182ff3898e7.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:48:44] "GET /media/cache/49/51/4951baa3676af7f6c7a930695d7bb9b1.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:48:44] "GET /media/cache/b6/2a/b62a10f4b59fbaba768f9dff39e24300.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:48:44] "GET /media/cache/c1/59/c1591c4d11a1f9457aae57db5543a728.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:48:44] "GET /media/cache/51/ad/51adaae437967af103322c6a8d506ed8.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/69/81/69812df34b543e84695d2fb81254ae7a.jpg HTTP/1.1" 301 0
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/dc/1f/dc1fb825d31a93fa3842e6009768bbd7.jpg HTTP/1.1" 301 0
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/44/0b/440b37e962da20f9be431bedbea6b396.jpg HTTP/1.1" 301 0
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/e8/25/e825db20363a63ae012c2182ff3898e7.jpg HTTP/1.1" 301 0
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/69/3e/693e37fb3f53f61edfe1bec9d4e22d2b.jpg HTTP/1.1" 301 0
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/49/51/4951baa3676af7f6c7a930695d7bb9b1.jpg HTTP/1.1" 301 0
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/b6/2a/b62a10f4b59fbaba768f9dff39e24300.jpg HTTP/1.1" 301 0
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/c1/59/c1591c4d11a1f9457aae57db5543a728.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/51/ad/51adaae437967af103322c6a8d506ed8.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/69/81/69812df34b543e84695d2fb81254ae7a.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/dc/1f/dc1fb825d31a93fa3842e6009768bbd7.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/44/0b/440b37e962da20f9be431bedbea6b396.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:48:44] "GET /en-gb/media/cache/e8/25/e825db20363a63ae012c2182ff3898e7.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:48:45] "GET /en-gb/media/cache/69/3e/693e37fb3f53f61edfe1bec9d4e22d2b.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:48:45] "GET /en-gb/media/cache/49/51/4951baa3676af7f6c7a930695d7bb9b1.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:48:45] "GET /en-gb/media/cache/b6/2a/b62a10f4b59fbaba768f9dff39e24300.jpg/ HTTP/1.1" 404 2813

我提交表单但Django没有重新执行代码:

[06/Apr/2015 20:49:38] "POST /en-gb/ HTTP/1.1" 200 8802
[06/Apr/2015 20:49:38] "GET /media/cache/dc/1f/dc1fb825d31a93fa3842e6009768bbd7.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:49:38] "GET /media/cache/69/81/69812df34b543e84695d2fb81254ae7a.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:49:38] "GET /media/cache/44/0b/440b37e962da20f9be431bedbea6b396.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:49:38] "GET /media/cache/69/3e/693e37fb3f53f61edfe1bec9d4e22d2b.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:49:38] "GET /media/cache/49/51/4951baa3676af7f6c7a930695d7bb9b1.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:49:38] "GET /media/cache/e8/25/e825db20363a63ae012c2182ff3898e7.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:49:38] "GET /media/cache/b6/2a/b62a10f4b59fbaba768f9dff39e24300.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:49:38] "GET /media/cache/c1/59/c1591c4d11a1f9457aae57db5543a728.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:49:38] "GET /media/cache/51/ad/51adaae437967af103322c6a8d506ed8.jpg HTTP/1.1" 302 0
[06/Apr/2015 20:49:39] "GET /en-gb/media/cache/dc/1f/dc1fb825d31a93fa3842e6009768bbd7.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:49:39] "GET /en-gb/media/cache/69/81/69812df34b543e84695d2fb81254ae7a.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:49:39] "GET /en-gb/media/cache/69/3e/693e37fb3f53f61edfe1bec9d4e22d2b.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:49:39] "GET /en-gb/media/cache/44/0b/440b37e962da20f9be431bedbea6b396.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:49:39] "GET /en-gb/media/cache/e8/25/e825db20363a63ae012c2182ff3898e7.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:49:39] "GET /en-gb/media/cache/49/51/4951baa3676af7f6c7a930695d7bb9b1.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:49:39] "GET /en-gb/media/cache/b6/2a/b62a10f4b59fbaba768f9dff39e24300.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:49:39] "GET /en-gb/media/cache/c1/59/c1591c4d11a1f9457aae57db5543a728.jpg/ HTTP/1.1" 404 2813
[06/Apr/2015 20:49:39] "GET /en-gb/media/cache/51/ad/51adaae437967af103322c6a8d506ed8.jpg/ HTTP/1.1" 404 2813

如果我坚持多次提交表单,它将执行代码并始终显示感谢模板。 我不明白问题出在哪里。

1 个答案:

答案 0 :(得分:0)

解决了为每个页面添加视图并删除:

url(r'^', include('cms.urls')),
来自urls.py