我的Web应用程序是Django,Web服务器使用Nginx,使用Docker镜像和Elastic Beanstalk进行部署.
通常没有问题,但随着负载均衡器扩展EC2,我的Web服务器变为502 Bad Gateway.
我检查了Elastic Beanstalk应用程序日志,大约16%的请求返回了5xx错误,此时负载均衡器扩展了EC2,导致Web服务器转换到502 Bad Gateway状态,Elastic Beanstalk应用程序转换为Degraded状态.
当负载均衡器执行运行状况检查时,这是一个常见问题吗?如果没有,如何关闭健康检查?
我附上了一张拍摄的图像供参考.
python deployment django amazon-web-services amazon-elastic-beanstalk
概述
带有查询参数的 url 看起来像。
http://example.api.com/search/?name=jhon&age=26
Run Code Online (Sandbox Code Playgroud)
如果我使用django-filter,所有参数都会自动从请求中提取,并且它会返回一个过滤后的查询集。
视图.py
class SearchView(TemplateView):
template_name = "search.html"
def get_queryset(self):
return SearchFilter(request.GET, queryset=Model.objects.all()).qs
def get_context_data(self, **kwargs):
context = super(SearchView, self).get_context_data(**kwargs)
return context
Run Code Online (Sandbox Code Playgroud)
如果我想从 request.GET 手动提取它,我可以做到。
def get_queryset(self):
# extracting query parameter
q = self.request.GET.get('name')
Run Code Online (Sandbox Code Playgroud)
问题陈述
我的搜索网址看起来像
http://example.api.com/search/jhon-26
Run Code Online (Sandbox Code Playgroud)
我这样做是因为我不想向公众透露诸如“姓名”和“年龄”之类的键,这是为了安全抽象,这些是我的数据库表的列。
我正在进入jhon-26
**kwargs,我想将其拆分并设置为 request.GET 的查询参数,以便我的过滤器类可以正常工作
题
有什么可以设置 request.GET 属性的吗?
# may be any set function available for this
self.request.GET.set('name', 'jhon')
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点。
例如,在重定向之前,我使用
messages.add_message(request, messages.INFO, 'You have successfully updated your listing.')
Run Code Online (Sandbox Code Playgroud)
然后重定向后消息会自动显示,但是消息永远不会消失,我可以知道如何在几秒钟后隐藏它吗?
谢谢!!!
您好,我想知道如何拆分字典值字符串
这是我的爬虫,它返回字典数据看起来像
data = {
{0:'http://..., product name, product price'},
{1:'http://...2, product name2, product price2'},
{N:'http://...2, product name2, product price n'}
}
Run Code Online (Sandbox Code Playgroud)
我想用逗号分割这些数据,例如,
for value in data.values():
href, product_name, product_price = str(value).split(",")
Run Code Online (Sandbox Code Playgroud)
在姜戈
这是我的 crawler.py
import requests
from urllib import parse
from bs4 import BeautifulSoup
def spider(item_name):
url_item_name = parse.quote(item_name.encode('euc-kr'))
url = 'http://search.11st.co.kr/SearchPrdAction.tmall?method=getTotalSearchSeller&isGnb=Y&prdType=&category=&cmd=&pageSize=&lCtgrNo=&mCtgrNo=&sCtgrNo=&dCtgrNo=&fromACK=recent&semanticFromGNB=&gnbTag=TO&schFrom=&schFrom=&ID=&ctgrNo=&srCtgrNo=&keyword=&adUrl=&adKwdTrcNo=&adPrdNo=&targetTab=T&kwd=' + url_item_name
resp = requests.get(url)
resp.raise_for_status()
resp.encoding='euc-kr'
plain_text = resp.text
soup = BeautifulSoup(plain_text, 'lxml')
mytag = soup.find_all(True, {"class": ["sale_price", "list_info"]})
#for link in soup.select('div.list_info p.info_tit a') : …
Run Code Online (Sandbox Code Playgroud) 我有一个包含大量数据的选择字段,我在管理面板创建了下拉菜单,但我想要一个可搜索的下拉菜单。
class ItemForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PublicUserForm, self).__init__(*args, **kwargs)
self.fields['city'] = forms.ChoiceField(
choices = CHOOSE_CITY)
class ItemAdmin(admin.ModelAdmin):
form = ItemForm
admin.site.register(Item, ItemAdmin)
Run Code Online (Sandbox Code Playgroud)
我已经推荐了django-autocomplete-light。
提前致谢!
django django-models django-forms django-admin django-autocomplete-light
编写一个带有music_func
3个参数音乐类型,音乐组,歌手的功能,并将它们全部打印出来,如下例所示.
如果用户没有提供输入,则该功能应该为参数设置这些值:"Classic Rock","The Beatles","Freddie Mercury".
例如:
输入:
Alternative Rock,Pearl Jam,Chris Cornell
Run Code Online (Sandbox Code Playgroud)
输出:
The best kind of music is Alternative Rock
The best music group is Pearl Jam
The best lead vocalist is Chris Cornell
Run Code Online (Sandbox Code Playgroud)
注意: print语句将进入music_func().例如:
print("The best kind of music is" + ...)
#definition for music_func goes here
def music_func(a,b,c):
if a is None or b is None or c is None:
print("The best kind of music is Classic Rock")
print("The best music group is …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Django+tenant_schemas,我的应用程序的本地版本运行良好。但是,当我尝试将其推送到暂存(Heroku+Docker)时,出现以下错误:
AttributeError: “DatabaseWrapper”对象没有属性“set_schema_to_public”(tenat_schemas)。
代码指向:
tenant_schemas/middleware.py in process_request at line 46:
connection.set_schema_to_public()
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我会收到这个错误。任何建议将不胜感激。谢谢
django-simple-history
书写历史改变instance.save()
方法。但是当我写迁移更改实例数据时,更改没有出现。
是save()
的方法
Model = apps.get_model('myapp', 'MyModel')
Run Code Online (Sandbox Code Playgroud)
和
MyModel
Run Code Online (Sandbox Code Playgroud)
一样吗?有没有办法将这种变化写入历史?
我有这个post_list.html文件:(忽略第二个'blog:post_detail'网址)
{% for post in post_list %}
<h1><a href="{% url 'blog:post_detail' post.pk %}">{{ post.title }}</a></h1>
<div class="date">
<p>Published on: {{post.published|date:"D M Y"}}</p>
</div>
<a href="{url 'blog:post_detail' post.pk}">Comments: {{post.approve_comments.count}}</a>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
在urls.py中,我尝试通过以下方式使用re_path:
re_path(r'^posts/<int:pk>/$', views.PostDetailView.as_view(), name='post_detail'),
Run Code Online (Sandbox Code Playgroud)
当我运行服务器时,我在/错误处获取NoReverseMatch:Reverse for 'post_detail' with arguments '(1,)' not found. 1 pattern(s) tried: ['posts/<int:pk>/$']
但是如果我更换re_path与网址,并<int:pk>
用(?P<pk>\d+)
它完美:
url(r'^posts/(?P<pk>\d+)/$', views.PostDetailView.as_view(), name='post_detail'),
Run Code Online (Sandbox Code Playgroud) django ×8
python ×5
deployment ×1
django-admin ×1
django-forms ×1
docker ×1
function ×1
heroku ×1
http ×1
if-statement ×1
javascript ×1
multi-tenant ×1
request ×1