这是一个愚蠢的问题。我刚刚创建了一个项目,并一直试图找出这个问题。
from django.conf.urls import url
from django.views.generic import TemplateView
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name="index.html")),
url(r'^about$', TemplateView.as_view(template_name="about.html")),
url(r'^contact$', TemplateView.as_view(template_name="contact.html"), name="contact"),
url(r'^test$', TemplateView.as_view(template_name="test_start"), name="test_start"),
url(r'^test/sample$', TemplateView.as_view(template_name="test_start"), name="test_start"),
]
Run Code Online (Sandbox Code Playgroud)
被纳入
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('frontend.urls'))
]
Run Code Online (Sandbox Code Playgroud)
当我去时localhost:8000/about
,我被重定向到localhost:8000/about/
那里,我得到 404 Not Found。
更新:我在 URLconf 中添加了更多 URL。
更新 2:我的意思是不包括尾部斜杠。我很抱歉。
更新 3:我在 Firefox 中打开了相同的 URL,该 URL 的工作原理与我预期的一样。这可能是重定向和浏览器缓存的问题吗?
我正在使用通常的./manage.py运行服务器在Cloud9中运行我的Django应用程序以进行开发.但对于外部世界,可通过https:// URL访问该应用.
问题是,当我使用URL反向函数时,返回的URL以http://开头(至少在某些时候).当我尝试重定向到其中一个URL时,我在控制台中收到类似这样的错误:
Mixed Content: The page at 'https://apps.facebook.com/xxxx/'
was loaded over HTTPS, but requested an insecure form action
'http://xxxx.c9users.io/facebook_app/gift_shop/'.
This request has been blocked; the content must be served over HTTPS.
Run Code Online (Sandbox Code Playgroud)
我的问题:有没有办法强制反向生成HTTPS URL而不是HTTP?
这是一段代码,从HTTPS URL到HTTP的重定向存在问题:
class IndexRedirectView(RedirectView, CSRFExemptMixin):
permanent = False
def get_redirect_url(self, *args, **kwargs):
if self.request.user.visit_count >= 5:
return reverse('gift-shop')
if len(BaseGiftableInstance.objects.filter(giving_user=self.request.user)) > 0:
# has won something
return reverse('gift-shop')
return reverse('spinner')
Run Code Online (Sandbox Code Playgroud) 我想将一个字符串分成几部分
Hello, what is up?
Run Code Online (Sandbox Code Playgroud)
变
["Hello,", " ", "what", " ", "is", " ", "up?"]
Run Code Online (Sandbox Code Playgroud)