tastypie

Whats the simplest and safest method to generate a API KEY and SECRET in Python

烂漫一生 提交于 2020-07-31 18:26:08
问题 I need to generate a API key and Secret that would be stored in a Redis server. What would be the best way to generate a key and secret? I am develop a Django-tastypie framework based app. 回答1: EDIT: for a very secure way of generating random number, you should use urandom: from binascii import hexlify key = hexlify(os.urandom(length)) this will produce bytes, call key.decode() if you need a string You can just generate keys of your desired length the python way: import random import string

Whats the simplest and safest method to generate a API KEY and SECRET in Python

你。 提交于 2020-07-31 18:26:08
问题 I need to generate a API key and Secret that would be stored in a Redis server. What would be the best way to generate a key and secret? I am develop a Django-tastypie framework based app. 回答1: EDIT: for a very secure way of generating random number, you should use urandom: from binascii import hexlify key = hexlify(os.urandom(length)) this will produce bytes, call key.decode() if you need a string You can just generate keys of your desired length the python way: import random import string

django-tastypie 笔记

拟墨画扇 提交于 2020-02-29 12:33:00
class Meta: queryset = User.objects.all() resource_name = 'user' #limit 默认 获取数据数量 20 limit = 10 #不显示字段 # excludes = ['email','password',] #需要显示的字段 fields = ['username', 'first_name', 'last_name', 'last_login', ] #methods allowed_methods = ['get', 'post', ] #可排序字段 order_by = all_name ordering = ['id', ] #可过滤字段 同django一样 filtering = { 'username':ALL, } #API methods url config v1_api = Api(api_name='v1') v1_api.register(EntryResource()) v1_api.register(UserResource()) urlpatterns = patterns('', url(r'^api/',include(v1_api.urls)), ) GET #http://localhost:8000/api/v1/entry/ 列表数据 url_name + api_name

How to represent unique together in Tastypie

99封情书 提交于 2020-01-25 07:35:32
问题 I have a Model structure that keeps track of following and followers of a User. class Connections(models.Model): following = models.ForeignKey( User, related_name='following' ) followers = models.ForeignKey( User, related_name='followers' ) class Meta: unique_together = (('following', 'followers'), ) Post models class Post(models.Model): body = models.TextField() user = models.ForeignKey(User) #media = models.ForeignKey(postMedia) post_image = models.ImageField(upload_to=get_postimage_path)

django-tastypie PATCH gives me a “400 (Bad Request)”

与世无争的帅哥 提交于 2020-01-23 02:35:05
问题 I am running a Django site on Apache which is front'ed by Nginx instance to serve my static media. I expose an API via django-tastypie to a model that I need to PATCH a field on. When I do local testing (via the django runserver) everything works as expected. On the live server however I get "400 (Bad Request)" returned. I've read a few places saying that Nginx does not support PATCH? Is that right? Is there a good workaround for this? Am I doing something wrong? I only send through the

exclude some fields in tastypie post data

馋奶兔 提交于 2020-01-15 10:29:31
问题 recently i start an API for my project by django-tastypie . actually I want to exclude some field requirement in post requests. Assume that my model have four fields and all of them defined as require in django model. But I want to receive two of them from API request and 2 others will be filled by my functions. So, how could I tell to tastypie to receive just those two fields and skip others? 回答1: If you want to exclude same fields you can do that by define it in the meta class of the

POST request to Tastypie returns a non-SSL Location Header

送分小仙女□ 提交于 2020-01-13 04:37:07
问题 I am doing a POST request to my Tastypie api, which creates a resource. It normally returns the resource uri, through the Location header in the response. The problem I'm having is the Location header contains a non-ssl url, even though my initial request (and the whole of my application) is under https. From my request headers: URL: https://example.com/api/v1/resource/ From my response headers: Location: http://example.com/api/v1/resource/80/ Because this is a reusable application that is

TastyPie Authentication from the same server

孤者浪人 提交于 2020-01-06 08:17:05
问题 I have an API in TastyPie thats consumed on the same domain. I only want to allow requests to come from my server. TastyPie has a number of different Authentication options, however I cannot use Session Authentication because no one logs in and a API Key could be view in my script. So I was thinking that I could somehow validate the post with a with Django csrf token . Is this possible any examples (I've search) or is there an option I have missed? 回答1: This answer provides the following

Nesting tastypie UserProfileResource and UserResource, null value in column \“user_id\” violates not-null constraint

十年热恋 提交于 2020-01-05 08:43:17
问题 This is my setup: class UserProfile(models.Model): user = models.OneToOneField(User, unique=True, related_name="profile") class UserProfileResource(ModelResource): class Meta: queryset = UserProfile.objects.all() resource_name = 'profile' authorization = Authorization() class UserResource(ModelResource): profile = fields.ToOneField(UserProfileResource, attribute='userprofile', related_name='user', full=True, null=True) class Meta: queryset = User.objects.all() resource_name = 'user'

Using tastypie api from other views

别说谁变了你拦得住时间么 提交于 2020-01-05 06:47:31
问题 I am calling tastypie api from normal django views. def test(request): view = resolve("/api/v1/albumimage/like/user/%d/" % 2 ) accept = request.META.get("HTTP_ACCEPT") accept += ",application/json" request.META["HTTP_ACCEPT"] = accept res = view.func(request, **view.kwargs) return HttpResponse(res._container) Using tastypie resource in view Call an API on my server from another view achieve the same thing but seems harder. Is my way of calling api acceptable? Besides, it would be awesome if I