本文整理匯總了Python中django.conf.settings.SITE_URL屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.SITE_URL屬性的具體用法?Python settings.SITE_URL怎麽用?Python settings.SITE_URL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.SITE_URL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def create(self, validated_data):
password = get_random_string(10)
user = User.objects.create_user(**validated_data)
# user = super().create(**validated_data)
user.set_password(password)
user.save()
username = validated_data["username"]
permissions = "管理員" if validated_data["is_staff"] else "普通用戶"
try:
send_mail("CMDB 用戶創建成功",
"Hi, {}, 您的CMDB用戶已成功創建:\n\t用戶名:{}\n\t權限:{}\n\t初始密碼:{}\n\t網站地址:{}".format(
username, username, permissions, password, settings.SITE_URL),
settings.SEND_EMAIL,
[validated_data["email"]],
fail_silently=False)
except Exception as exc:
logger.error(f"用戶創建成功 郵件發送失敗 {exc}")
raise exceptions.ParseError("用戶創建成功 郵件發送失敗")
return user
# def update(self, instance, validated_data):
# super().update(instance, validated_data)
# if "password" in validated_data:
# instance.set_password(validated_data)
# return instance
示例2: is_already_short
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def is_already_short(url):
popular_shortening_urls = [
'bit.ly/',
'goo.gl/',
'ow.ly/',
'is.gd/',
'buff.ly/',
'adf.ly/',
'tinyurl.com/',
'bit.do/',
'mcaf.ee/',
't.co/',
'tiny.cc/',
'shorte.st/',
'idek.net/',
'po.st/',
'yep.it/',
'tr.im/',
settings.SITE_URL,
]
for shortening_url in popular_shortening_urls:
if shortening_url in url:
return True
return False
示例3: full_url
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def full_url(url):
"""
A Django template filter to prepend the given URL path with the full
site URL.
"""
return urljoin(settings.SITE_URL, url)
示例4: add_site
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def add_site(apps, schema_editor):
Site = apps.get_model("sites", "Site")
db_alias = schema_editor.connection.alias
domain = urlparse(settings.SITE_URL)
Site.objects.using(db_alias).get_or_create(
id=settings.SITE_ID, defaults={"domain": domain.netloc, "name": domain.netloc}
)
示例5: prefetch_page_task
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def prefetch_page_task(base_url=None, maxdepth=2):
""" Prefetch pages, breadth-first, to populate the cache. """
if not settings.ENABLE_CACHING:
logger.info("Caching disabled -- not prefetching")
return
if not base_url:
base_url = settings.SITE_URL
if not base_url.endswith('/'):
base_url += '/'
to_visit = deque()
to_visit.append((base_url, 0))
visited = set()
while len(to_visit) > 0:
url, depth = to_visit.popleft()
visited.add(url)
if not url.startswith(base_url):
continue
try:
start = time()
text = urllib2.urlopen(url).read()
elapsed = time() - start
logger.info('prefetch (%s, %.3f s): %s' % (depth, elapsed, url))
except Exception as exc:
logger.error(
'prefetch (%s): error fetching %s: %s' % (depth, url, exc))
return
if depth < maxdepth:
try:
html = lxml.html.fromstring(text)
except Exception as exc:
logger.error(
'prefetch (%s): error parsing %s: %s' % (depth, url, exc))
continue
html.make_links_absolute(url)
for element, attribute, link, pos in html.iterlinks():
if (attribute.lower() == 'href' and link.endswith('/') and
link not in visited):
to_visit.append((link, depth + 1))
示例6: external_task_url
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def external_task_url(self):
if settings.ENABLE_SSL:
# SSL certificates are under the host name
base_url = settings.SITE_URL
else:
# use raw IP for faster page loads -- a fresh DNS lookup can take
# as long as 6s in India for some DNS servers
base_url = 'http://' % settings.SERVER_IP
return base_url + reverse('mturk-external-task', args=(self.id,))
示例7: get_url
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def get_url(self):
config = Configuration.get_solo()
relative_url = reverse(
"public:memberpage:member.dashboard",
kwargs={"secret_token": self.secret_token},
)
if config.public_base_url:
return urljoin(config.public_base_url, relative_url)
else:
return urljoin(settings.SITE_URL, relative_url)
示例8: _sign
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def _sign(self, q, a, expires):
plain = [getattr(settings, "SITE_URL", ""), settings.SECRET_KEY, q, a, expires]
plain = "".join([str(p) for p in plain])
return sha1(plain.encode("utf-8")).hexdigest()
示例9: item_author_link
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def item_author_link(self, item):
return settings.SITE_URL + item.user.get_absolute_url()
示例10: settings_context_processor
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def settings_context_processor(request):
return {
'SITE_NAME': settings.SITE_NAME,
'SITE_DOMAIN': settings.SITE_DOMAIN,
'SITE_URL': settings.SITE_URL
}
示例11: get_external_url
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def get_external_url(self):
url = "{}{}".format(settings.SITE_URL, self.get_absolute_url())
return url
示例12: report_content_url
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def report_content_url(context):
"""
Get URL to report content form with the current URL attached to it
"""
request = context['request']
# We use only the path here, ignoring all GET parameters
source_url = settings.SITE_URL + request.path
return reverse('contact:report_content') + '?source=' + quote_plus(source_url)
示例13: client_loan_application
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def client_loan_application(request, client_id):
form = LoanAccountForm()
client = get_object_or_404(Client, id=client_id)
group = Group.objects.filter(clients__id__in=client_id).first()
account_no = unique_random_number(LoanAccount)
loan_pay = LoanRepaymentEvery.objects.all()
if request.method == 'POST':
form = LoanAccountForm(request.POST)
if form.is_valid():
loan_account = form.save(commit=False)
loan_account.status = "Applied"
loan_account.created_by = User.objects.get(username=request.user)
loan_account.client = client
interest_charged = d(
(
d(loan_account.loan_amount) * (
d(loan_account.annual_interest_rate) / 12)
) / 100
)
loan_account.principle_repayment = d(
int(loan_account.loan_repayment_every) * (
d(loan_account.loan_amount) / d(
loan_account.loan_repayment_period)
)
)
loan_account.interest_charged = d(
int(loan_account.loan_repayment_every) * d(interest_charged))
loan_account.loan_repayment_amount = d(
d(loan_account.principle_repayment) + d(
loan_account.interest_charged)
)
loan_account.total_loan_balance = d(d(loan_account.loan_amount))
if group:
loan_account.group = group
loan_account.save()
if client.email and client.email.strip():
send_email_template(
subject="Your application for the Personal Loan (ID: %s) has been Received." % loan_account.account_no,
template_name="emails/client/loan_applied.html",
receipient=client.email,
ctx={
"client": client,
"loan_account": loan_account,
"link_prefix": settings.SITE_URL,
},
)
return JsonResponse({"error": False, "loanaccount_id": loan_account.id})
else:
return JsonResponse({"error": True, "message": form.errors})
context = {
'form': form, 'client': client, 'account_no': account_no,
'loan_repayment_every': loan_pay
}
return render(request, "client/loan/application.html", context)
示例14: change_loan_account_status
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def change_loan_account_status(request, pk):
# if request.method == 'POST':
loan_object = get_object_or_404(LoanAccount, id=pk)
if loan_object:
branch_id = loan_object.group.branch.id
elif loan_object.client:
branch_id = loan_object.client.branch.id
else:
branch_id = None
if branch_id:
if (request.user.is_admin or
(request.user.has_perm("branch_manager") and
request.user.branch.id == branch_id)):
status = request.GET.get("status")
if status in ['Closed', 'Withdrawn', 'Rejected', 'Approved']:
loan_object.status = request.GET.get("status")
loan_object.approved_date = datetime.datetime.now()
loan_object.save()
if loan_object.client:
if loan_object.status == 'Approved':
if loan_object.client.email and loan_object.client.email.strip():
send_email_template(
subject="Your application for the Personal Loan (ID: %s) has been Approved." % loan_object.account_no,
template_name="emails/client/loan_approved.html",
receipient=loan_object.client.email,
ctx={
"client": loan_object.client,
"loan_account": loan_object,
"link_prefix": settings.SITE_URL,
},
)
elif loan_object.group:
group_member_loans = GroupMemberLoanAccount.objects.filter(group_loan_account=loan_object)
group_member_loans.update(status=loan_object.status)
group_member_loans.update(loan_issued_date=loan_object.loan_issued_date)
group_member_loans.update(interest_type=loan_object.interest_type)
for client in loan_object.group.clients.all():
if client.email and client.email.strip():
send_email_template(
subject="Group Loan (ID: %s) application has been Approved."
% loan_object.account_no,
template_name="emails/group/loan_approved.html",
receipient=client.email,
ctx={
"client": client,
"loan_account": loan_object,
"link_prefix": settings.SITE_URL,
},
)
data = {"error": False}
else:
data = {"error": True, "error_message": "Status is not in available choices"}
else:
data = {"error": True, "error_message": "You don't have permission to change the status."}
else:
data = {"error": True, "error_message": "Branch Id not Found"}
data["success_url"] = reverse('loans:clientloanaccount', kwargs={"pk": loan_object.id})
return JsonResponse(data)
示例15: shorten_url
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SITE_URL [as 別名]
def shorten_url(request):
url = request.POST.get("url", '')
alias = request.POST.get("alias")
valid_url,url=validate_url(url)
if valid_url:
if alias !='':
for rec in record:
if record[rec]==alias:
return HttpResponse(json.dumps({"error":"error occurs", 'alias':-1, 'url':url}),content_type="application/json")
if url in record:
short_id = record.get(url)
if alias !='' and alias != short_id:
b = urls.objects.get(pk=short_id)
b.short_id=alias
b.save()
short_id = alias
record[url]=alias
response_data = {}
response_data['url'] = settings.SITE_URL + "/" + short_id
return HttpResponse(json.dumps(response_data), content_type="application/json")
else:
# check whether input is already short
if is_already_short(url):
response_data = {}
return HttpResponse(json.dumps({"already_short": True}), content_type="application/json")
elif alias == '':
short_id = get_short_code()
record.update({url:short_id})
b = urls(httpurl=url, short_id=short_id)
b.save()
response_data = {}
response_data['url'] = settings.SITE_URL + "/" + short_id
return HttpResponse(json.dumps(response_data), content_type="application/json")
else:
record.update({url:alias})
b = urls(httpurl=url, short_id=alias)
b.save()
response_data={}
response_data['url'] = settings.SITE_URL + "/" + alias
return HttpResponse(json.dumps(response_data), content_type="application/json")
return HttpResponse(json.dumps({"error": "error occurs", "valid_url":valid_url,'url':url}), content_type="application/json")