用户名和密码在wkhtmltopdf应用程序中不起作用

时间:2014-04-01 05:57:28

标签: django-forms wkhtmltopdf html-to-pdf

我需要使用终端上的wkhtmltopdf工具将HTML网址转换为pdf格式。

 $ wkhtmltopdf --username 'arya_normal2' --password '1' http://localhost:8000/employee/arya_normal2-no-emp-code/certificates/53/show/   localhost.pdf

点击url时未获得身份验证/登录。它给出了简单的登录pdf页面。

我已经使用我的Google帐户查看了它的pdf显示登录页面。

有人在wkhtmltopdf中使用过用户名和密码吗?如果我给出了错误的命令行参数,请帮助我。

修改

修改后的命令行参数:

  wkhtmltopdf --cookie 'csrftoken' 'JuQUFr9KLUdZLMAjLn3d8yakd6HOshTN' --cookie  'sessionid'  'xy3yacbe3nq1sbbtstkxfp34ah3imcmg'  --post username 'arya_normal2' --post password '1' http://localhost:8000/employee/arya_normal2-no-emp-code/certificates/all/   sample2.pdf

现在出现以下错误:

Internal Server Error: /employee/arya_normal2-no-emp-code/certificates/all/
Traceback (most recent call last):
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 107, in get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/middleware/csrf.py", line 170, in process_view
    request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 146, in _get_post
    self._load_post_and_files()
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/http/request.py", line 219, in _load_post_and_files
    self._post, self._files = self.parse_file_upload(self.META, data)
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/http/request.py", line 183, in parse_file_upload
    parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding)
  File "/home/nirmal/venvs/nuvologistics/local/lib/python2.7/site-packages/django/http/multipartparser.py", line 70, in __init__
    raise MultiPartParserError('Invalid boundary in multipart: %s' % boundary)
MultiPartParserError: Invalid boundary in multipart: None

登录表单:

<form action="" method="post" enctype="multipart/form-data"  boundary=0xKhTmLbOuNdArY>
         {% csrf_token %}

         <input name="username" type="text" placeholder="Email-address" id="email"><br>
         <input name="password" type="password" placeholder="Password" id="password"><br>
         <input type="checkbox" id="remember" value="Remember Me" >&nbsp; <span>Remember Me</span>
         <a id="forget">Forgot your Password?</a><br>
           {% if error %}
          <i class="icon-warning"></i><span class="error">The username or password you entered is incorrect.</span>
         {% endif %}
         <input type="submit" value="LOGIN" id="login">
     </form>

1 个答案:

答案 0 :(得分:0)

--post参数的正确语法是--post username user_name_value --post password password_value

在您的登录表单中,尝试更改为 id =“username”而不是id =“email”

用户名和密码均为 id 和表单上输入字段的名称

希望它有所帮助!

请参阅:Generate PDF Behind Authentication Wall