我试图运行一个简单的连接到pymongo但它一直返回,连接被拒绝
这是我尝试过的:
>>>from pymongo import Connection
>>>connection = Connection('localhost',27017)
Run Code Online (Sandbox Code Playgroud)
这就是我得到的
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.0.1_-py2.7-linux i686.egg/pymongo/connection.py", line 348, in __init__
self.__find_node()
File "/usr/local/lib/python2.7/dist-packages/pymongo-2.0.1_-py2.7-linux- i686.egg/pymongo/connection.py", line 627, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: could not connect to localhost:27017: [Errno 111] Connection refused
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
每当我的PHP代码出错时,MAMP只会返回500错误.无论如何,我可以让MAMP告诉我解决错误和东西出了什么问题?
我从几个博客中看到了有关此问题的混合答案.我听说此功能仅在Xcode 7在秋季发布时才可用,但同样有人说你现在可以在自己的设备上进行测试.如果可能的话,非常感谢任何指向优秀教程的链接.
我目前正在对我的API执行cURL POST请求
curl --dump-header - -H "Content-Type: application/json" -X POST --data '{"username":"theusername", "api_key":"anapikey", "video_title":"a title", "video_description":"the description"}' http://localhost:8000/api/v1/video/
Run Code Online (Sandbox Code Playgroud)
但现在我需要能够将视频文件添加到上传中.我一直在寻找有关使用Tastypie上传文件的几个小时,我还没有想出一个坚实的回复.我需要添加Base64编码吗?如果是这样的话?在我通过POST请求上传文件后如何访问该文件?只是正常的request.FILES动作?我不是要将文件保存到数据库,只是获取文件的路径.
#Models.py
class Video(models.Model):
video_uploader = models.ForeignKey(User)
video_path = models.CharField(max_length=128)
video_views = models.IntegerField(default=0)
upload_date = models.DateTimeField(auto_now_add=True)
video_description = models.CharField(max_length=860)
video_title = models.SlugField()
Run Code Online (Sandbox Code Playgroud)
我对如何为Tastypie实现文件上传系统感到非常困惑,所以任何帮助都将非常感激.谢谢!
我正在使用 Django 1.9 和 Python 2.7,我试图让我的应用程序识别用户是否正在使用移动设备浏览。我尝试过 django_mobile 但它对于 django 1.9 来说似乎已经过时了,因为甚至没有 template_loaders 来安装该应用程序,我对此有错吗?
我需要创建一个表单并让表单上传图像并将其保存到我的磁盘.这是我的代码
import web
urls = (
'/hello', 'Index',
'/file_upload_form', 'ThatFile'
)
app = web.application(urls, globals())
render = web.template.render('templates/', base = "layout")
class ThatFile(object):
def GET(self):
return render.file_upload_form()
def POST(self):
form = web.input(image = "loc")
open(form.image,'r')
image_o = form.image.read()
return render.thatfile(o_image = o_image)
class Index(object):
def GET(self):
return render.hello_form()
def POST(self):
form = web.input(name = "Nobody", greet = None)
greeting = "%s, %s" % (form.greet, form.name)
return render.index(greeting = greeting)
if __name__ == "__main__":
app.run()
Run Code Online (Sandbox Code Playgroud)
我尝试过使用PIL Image模块,但它不显示图像.
我正在研究一个django项目,当我尝试运行这个函数时,它返回只能给出一个参数,但是只给出了一个参数.
from django.http import HttpResponse, Http404
from django.template import Context
from django.template.loader import get_template
from django.contrib.auth.models import User
def main_page(request):
template = get_template('main_page.html')
variables = Context({
'head_title':u'Bookmarks!',
'page_title':u'Welcome to bookmarks!',
'page_body': u'store and share the bookmarks',
})
output = template.render(variables)
return HttpResponse(output)
Run Code Online (Sandbox Code Playgroud)
网址模式
from django.conf.urls.defaults import patterns, include, url
from socialnetwork.bookmarks.views import *
urlpatterns = patterns('',
(r'^user/(\w+)/$', main_page),
)
Run Code Online (Sandbox Code Playgroud)
追溯:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/user/Colin/
Django Version: 1.3
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages', …Run Code Online (Sandbox Code Playgroud) 当我可以从Django视图返回JSON时,为什么我要使用TastyPie?