簡體   English   中英

Django不會在POST提交的表單上重新執行代碼

[英]Django doesn't re-execute code on form submit by POST

我為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 /,其中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

如果我堅持多次提交表單,它將執行代碼,並始終顯示感謝模板。 我不明白問題出在哪里。

解決了為每個頁面添加視圖並刪除:

url(r'^', include('cms.urls')),

從urls.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM