因此,我的Django没有出现任何问题,并且在dev中响应URL路由,但是现在我正试图转移到生产中,遇到了各种各样的问题。
是的,说到regex我就很烂。它看起来像一只猫走在键盘上。当然,我需要坐下来专心学习。
在dev中,我的catch只是以下几个完美工作的地方:
url(r'', TemplateView.as_view(template_name='index.html')),在生产中,我得到了Uncaught SyntaxError: Unexpected token <。正如我所解释的,这与JS被抓到而不是index.html有关,JS需要“通过”。我被告知要尝试:
url(r'^$', TemplateView.as_view(template_name='index.html')),这个成功了。加载了web应用程序,我就可以导航了。
然而,当涉及到验证电子邮件链接时,出现了另一个问题。我遇到了Page not found (404)的问题,这在我的开发设置中也不是一个问题。
电子邮件链接如下所示:
https://test.example.com/auth/security_questions/f=ru&i=101083&k=6d7cd2e9903232a5ac28c956b5eded86c8cb047254a325de1a5777b9cca6e537
我得到的是:
Page not found (404) Requested URL: http://test.example.com/auth/security_questions/f%3Dru&i%3D101083&k%3D6d7cd2e9903232a5ac28c956b5eded86c8cb047254a325de1a5777b9cca6e537/
我的反应路线如下:
<App>
<Switch>
<Route exact path='/auth/security_questions/f=:f&i=:id&k=:key' component={SecurityQuestions} />
<Route exact path='/auth/*' component={Auth} />
<Route exact path='/' component={Auth} />
</Switch>
</App>这应该会呈现/auth/security_questions/...路由。
我的urls.py如下:
urlpatterns = [
# API authentication entry point
url(r'^api/auth/', include('authentication.urls', namespace='signin')),
# Any requets that come through serve the index.html
# url(r'^$', TemplateView.as_view(template_name='index.html')),
] + static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)另外,authentication.urls
urlpatterns = [
url(r'^security_questions/', SecurityQuestionsAPIView.as_view(), name='security_questions'),
]似乎Django正在尝试处理路由,显然没有匹配的路由,而实际上它应该只呈现index.html并让react-router-dom接管从FE发送请求到API。因此,我似乎需要一个让JS通过的捕获器。
我遇到了一个似乎相关的问题:react routing and django url conflict。因此,我添加了以下内容,这样我就有了一个/捕获,然后“所有-其他”捕获-所有。
# match the root
url(r'^$', TemplateView.as_view(template_name='index.html')),
# match all other pages
url(r'^(?:.*)/?$', TemplateView.as_view(template_name='index.html')),仍然不会呈现验证链接。为最后一个捕获所有URL尝试了其他几个变体:
Django route all non-catched urls to included urls.py
url(r'^', TemplateView.as_view(template_name='index.html')),
Uncaught SyntaxError: Unexpected token <的结果
url(r'^.*', TemplateView.as_view(template_name='index.html')),
见前文。
所以要深入到Django,regex,并试图解决这个问题,但同时.
,我在这里做错什么了?
发布于 2018-07-02 18:23:35
好的,就快到了。我修改了:
url(r'^(?:.*)/?$', TemplateView.as_view(template_name='index.html')),
对此:
url(r'^(?:.*)/$', TemplateView.as_view(template_name='index.html')),
从而防止了Uncaught SyntaxError: Unexpected token <错误。它将加载web应用程序的部分内容,但不会全部加载。这个问题是由于URL编码造成的,所以我不得不清理我的URL格式。我在这里有个问题:
Prevent URL encoding that is removing equals signs from URL
现在一切似乎都是正确的加载。
https://stackoverflow.com/questions/51109956
复制相似问题