我想在我的django应用程序中使用虚荣URL,即用户的个人资料在example.com/username
等网址。我试着这样做:
urlpatterns = patterns('',
#sitemap generation
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},name='django.contrib.sitemaps.views.sitemap'),
url(r'^grappelli/', include('grappelli.urls')), # grappelli URLS
url(r'^admin/', include(admin.site.urls)),
..other urls
#User Profile URLs
url(r'^(?i)(?P<username>[a-zA-Z0-9.-_]+)$','myapp.views.user_profile',name='user-profile'),
)
因为虚荣网址的url模式终于在urlpatterns中所以django应该在最后匹配它。但即使它与admin urls和user_profile视图冲突,也会呈现'example.com/admin'url而不是default.What是确保vanity-urls不与任何django-urls冲突的最佳方法?无论如何都要编写正则表达式,以便它排除django应用程序的现有URL集。
答案 0 :(得分:1)
您的中间件会将 Intent mediaIntent = new Intent(Intent.ACTION_PICK,MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
mediaIntent.setType("video/*"); //set mime type as per requirement
mediaIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(mediaIntent,4);
重定向到public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
try {
if (requestCode == 4 && resultCode == Activity.RESULT_OK) {
String filePath = "";
Uri _uri = data.getData();
filePath=getRealPathFromURI(_uri);
File org = new File(filePath);
File news=new File(saveFile());
copy (org,news);
}
} catch (Exception ex) {
Log.e("RESULT","ERROR",ex);
}
}
。这与管理员的正则表达式不匹配,仅适用于您的用户个人资料。使用此中间件,您无法访问管理员索引页面。
一种解决方案是仅在带有斜杠的旧路径无效且新路径有效时才重定向。