小编vai*_*312的帖子

AbstractUser Django完整的例子

我是Django的新手,我已经尝试了几周,但找不到解决这个问题的方法.

我想存储其他信息,如用户手机号码,银行名称,银行帐户.并希望在用户注册时存储手机号码,并希望用户使用(手机号码和密码)或(电子邮件和密码)登录.

这是我的UserProfile模型

from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractUser
# Create your models here.

class UserProfile(AbstractUser):

     user_mobile = models.IntegerField(max_length=10, null=True)
     user_bank_name=models.CharField(max_length=100,null=True)
     user_bank_account_number=models.CharField(max_length=50, null=True)
     user_bank_ifsc_code = models.CharField(max_length=30,null=True)
     user_byt_balance = models.IntegerField(max_length=20, null=True)
Run Code Online (Sandbox Code Playgroud)

这是我的forms.py

from django import forms            
from django.contrib.auth.models import User   # fill in custom user info then save it 
from django.contrib.auth.forms import UserCreationForm      
from models import UserProfile
from django.contrib.auth import get_user_model

class MyRegistrationForm(UserCreationForm):
    email = forms.EmailField(required = True)
    mobile = forms.IntegerField(required=True)



    class Meta:
        model = …
Run Code Online (Sandbox Code Playgroud)

django django-models django-users python-2.7 django-1.5

10
推荐指数
2
解决办法
1万
查看次数

如何在python中删除转义序列,如'\ xe2'或'\ x0c'

我正在研究一个项目(基于内容的搜索),因为我在Ubuntu中使用'pdftotext'命令行实用程序,它将所有文本从pdf写入一些文本文件.但是它也写了子弹,现在当我正在读取文件来索引每个单词时,它也会得到一些索引的转义序列(比如'\ x01').我知道它是因为子弹(•).

我只想要文本,所以有没有办法删除这个转义序列.我做过这样的事情

escape_char = re.compile('\+x[0123456789abcdef]*')
re.sub(escape_char, " ", string)
Run Code Online (Sandbox Code Playgroud)

但这不会删除转义序列

提前致谢.

python regex escaping string-literals

8
推荐指数
1
解决办法
7671
查看次数

Twitter Bootstrap就像垂直导航栏一样

我是bootstrap的新手,在创建像bootstrap这样的导航栏时遇到了问题.我花了很多时间尝试它,但无法弄明白.我想要的是什么

在此输入图像描述

这就是我在这里找到的

<div class="span3 bs-docs-sidebar">
<ul class="nav nav-list bs-docs-sidenav affix">
  <li class="active"><a href="#dropdowns"><i class="icon-chevron-right"></i> Dropdowns</a></li>
  <li class=""><a href="#buttonGroups"><i class="icon-chevron-right"></i> Button groups</a></li>
  <li><a href="#buttonDropdowns"><i class="icon-chevron-right"></i> Button dropdowns</a></li>
  <li><a href="#navs"><i class="icon-chevron-right"></i> Navs</a></li>
  <li><a href="#navbar"><i class="icon-chevron-right"></i> Navbar</a></li>
  <li><a href="#breadcrumbs"><i class="icon-chevron-right"></i> Breadcrumbs</a></li>
  <li><a href="#pagination"><i class="icon-chevron-right"></i> Pagination</a></li>
  <li><a href="#labels-badges"><i class="icon-chevron-right"></i> Labels and badges</a></li>
  <li><a href="#typography"><i class="icon-chevron-right"></i> Typography</a></li>
  <li><a href="#thumbnails"><i class="icon-chevron-right"></i> Thumbnails</a></li>
  <li><a href="#alerts"><i class="icon-chevron-right"></i> Alerts</a></li>
  <li><a href="#progress"><i class="icon-chevron-right"></i> Progress bars</a></li>
  <li><a href="#media"><i class="icon-chevron-right"></i> Media object</a></li>
  <li><a href="#misc"><i class="icon-chevron-right"></i> Misc</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

twitter-bootstrap

8
推荐指数
2
解决办法
6万
查看次数

将字符串转换为字典python

我想要一本字典

 >>> page_detail_string = urllib2.urlopen("http://graph.facebook.com/Ideas4India").read()
Run Code Online (Sandbox Code Playgroud)

它返回一个字符串

>>> page_detail_string
'{"about":"Ideas for development of India","category":"Community","description":"Platform where you can discuss and share your ideas which you think might help in betterment of our country.\\nPlease respect other community members and do not talk politics here.","is_published":true,"talking_about_count":0,"username":"Ideas4India","were_here_count":0,"id":"250014455083430","name":"Ideas 4 India","link":"http:\\/\\/www.facebook.com\\/Ideas4India","likes":23}'
Run Code Online (Sandbox Code Playgroud)

现在我想将它转换为字典,我可以使用ast.literal_eval轻松完成

>>> import ast
>>> dict_page = ast.literal_eval(page_detail_string)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/ast.py", line 80, in literal_eval
return _convert(node_or_string)
File "/usr/lib/python2.7/ast.py", line 63, in _convert
in zip(node.keys, node.values))
File …
Run Code Online (Sandbox Code Playgroud)

python string dictionary python-2.7

7
推荐指数
3
解决办法
3万
查看次数

Django 1.7中的用户名更长

我想将django中用户名的长度从30增加到80左右,我知道这可能是重复的问题,但之前的答案不起作用,例如https://kfalck.net/2010/12/30/longer-用户名换的Django

这是为Django 1.2.

有没有人为Django尝试类似的黑客> 1.5提前谢谢

django django-models django-users django-1.6 django-1.7

5
推荐指数
1
解决办法
2272
查看次数

youtube-dl python 脚本中的自定义用户代理

我有以下一段 python 代码,它调用 youtube-dl 并提取我需要的链接。

ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s%(ext)s'})

with ydl:
    result = ydl.extract_info(
        url,
        download=False
         # We just want to extract the info
    )

if 'entries' in result:
    # Can be a playlist or a list of videos
    video = result['entries'][0]
else:
    # Just a video
    video = result

if video:
    return video

return None
Run Code Online (Sandbox Code Playgroud)

但我想在这个程序中使用自定义用户代理。我知道我可以在命令行中使用 youtube-dl 时指定自定义用户代理。

有什么方法可以在嵌入 youtube-dl 的程序中指定自定义用户代理吗?

谢谢

python user-agent python-2.7 youtube-dl

4
推荐指数
1
解决办法
9165
查看次数

在python中从视频源创建视频缩略图

我有一个视频文件的 url,我想生成每个视频源 url 的缩略图。我正在使用 Django。

我的应用程序这样做: -

1. Crawl the some webpage
2. Extract all the video link from it.
3. If there are thumbnails, get those thumbnails.
4. if not thumbnails:
    #here I need to generate video thumbnails from the
    #links I extracted in 2nd step.
Run Code Online (Sandbox Code Playgroud)

有没有办法在不下载完整视频和生成缩略图的情况下做到这一点。

如果我下载每个视频,则会浪费大量带宽并需要大量时间。

谢谢

python django video video-thumbnails

2
推荐指数
1
解决办法
6869
查看次数

基于内容类型django 1.7的过滤器模型

我的models.py看起来像

class OneTimeEvent(models.Model):
    title = models.CharField(max_length = 160)
    location = models.CharField(max_length = 200, blank = True)
    event_date = models.DateTimeField('event date',blank = True, null = True)
    price = models.IntegerField(max_length = 20, blank = True, null = True)
    seats = models.IntegerField(max_length = 20, blank = True, null = True)
    abstract = models.TextField()
    event_plan = models.TextField()
    available_seats = models.IntegerField(max_length = 20, blank = True, null = True)
    booked_seats = models.IntegerField(max_length = 20, blank = True, null = True)
    byt_url = models.CharField(max_length = 160, …
Run Code Online (Sandbox Code Playgroud)

django django-models django-contenttypes django-1.7

1
推荐指数
1
解决办法
1394
查看次数