如何在Python中获取POST参数?

时间:2015-07-23 08:43:12

标签: python django post

我是Python的新手,并且不知道我的语法有什么问题。 这些是我在views.py上编写的代码。

@csrf_exempt
def userRegister(request):
    user = UserInfo (
        nickName = request.POST['nick'],
        email = request.POST['email'],
        pw = request.POST['pw'],
        regDt = timezone.now()
    )
    user.save()

    picture = ProfilePicture(
        imgUrl = request.POST['url']
    )
    picture.save()

    detail = UserDetail(
        memo = request.POST['memo']
    )
    detail.save()
    return HttpResponse("NoErr")

我的models.py中有3个课程。

class UserInfo(models.Model):
     nickName = models.CharField(max_length = 12)
     email = models.CharField(max_length = 50)
     pw = models.CharField(max_length = 64)
     regDt = models.DateTimeField('date published')


class ProfilePicture(models.Model):
     imgUrl = models.CharField(max_length = 100)


class UserDetail(models.Model):
     memo = models.CharField(max_length = 200)

当我尝试调用userRegister时,它显示500错误结束原因是此行imgUrl = request.POST['url']上的python语法错误。 这有什么问题?

加入

这些是追溯

回溯:

File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  108.                 response = middleware_method(request)
File "/Library/Python/2.7/site-packages/django/middleware/common.py" in process_request
  74.             if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in is_valid_path
  647.         resolve(path, urlconf)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in resolve
  522.     return get_resolver(urlconf).resolve(path)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in resolve
  366.             for pattern in self.url_patterns:
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  402.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  396.             self._urlconf_module = import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/Users/Lou/Desktop/WorkProject/test/testsite/testsite/urls.py" in <module>
  21.     url(r'^memberRegister/', include('memberRegister.urls')),
File "/Library/Python/2.7/site-packages/django/conf/urls/__init__.py" in include
  33.         urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)

Exception Type: SyntaxError at /memberRegister/reg
Exception Value: EOL while scanning string literal (urls.py, line 23)

这是主要的urls.py。

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^memberRegister/', include('memberRegister.urls')),

]

这是memberRegister / urls.py。

urlpatterns = [
    url(r'^$', views.welcome, name = 'welcome'),
    url(r'^hi', views.hi, name='hi'),
    url(r'^hello', views.hello, name='hello'),
    url(r'^reg', views.userRegister, name='userRegister'),
]

欢迎,嗨,你好工作正常。

0 个答案:

没有答案