我是 Python Django 的新手,我已经成功创建了我的应用程序,当我尝试在 Ubuntu 16.04 上托管我的 Django 应用程序时,它无法正常工作,我尝试了几种方法并用 Google 搜索了很多,请帮助摆脱这种情况。
\n\n我按照这个 URL How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu我已经正确完成了所有设置,但仍然没有成功。在这里我分享必要的文件供您参考,如果我遗漏了什么,请告诉我。
\n\netc/nginx/站点可用
\n\nserver {\n listen *:91;\n server_name ip-address;\n location = /favicon.ico { access_log off; log_not_found off; }\n location /static/ {\n root /home/iradmin/django/scm;\n }\n location / {\n include proxy_params;\n proxy_pass http://unix:/home/iradmin/django/scm/scm.sock;\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n等/inint/gunicorn.conf
\n\ndecription "Gunicorn application server handling scm"\nstart on runlevel [2345]\nstop on runlevel [!2345]\nrespawn\nsetuid iradmin\nsetgid www-data\nchdir /home/iradmin/django/scm/\nexec python3venv/bin/gunicorn --workers 3 …Run Code Online (Sandbox Code Playgroud) 我有一些外部服务。我的 Django 应用程序建立在我的外部服务 API 之上。为了与我的外部服务对话,我必须传入一个 auth cookie,我可以通过读取User(那个 cookie != django cookie)来获取它。
使用测试工具,例如webtests,requests我有麻烦写我的测试。
class MyTestCase(WebTest):
def test_my_view(self):
#client = Client()
#response = client.get(reverse('create')).form
form = self.app.get(reverse('create'), user='dummy').form
print form.fields.values()
form['name'] = 'omghell0'
print form
response = form.submit()
Run Code Online (Sandbox Code Playgroud)
我需要提交一个表单,它会在我的外部服务上创建一个用户。但要做到这一点,我通常会传入request.user(以验证我对外部服务的特权)。但我没有request.user。
对于这种东西,我有什么选择?
谢谢...
假设这是我的tests.py
import unittest
from django.test.client import Client
from django.core.urlresolvers import reverse
from django_webtest import WebTest
from django.contrib.auth.models import User
class SimpleTest(unittest.TestCase):
def setUp(self):
self.usr = User.objects.get(username='dummy')
print self.usr
.......
Run Code Online (Sandbox Code Playgroud)
我得到
Traceback …Run Code Online (Sandbox Code Playgroud)