How can I make a main URL with sub URL for different Django app? - python-3.x

I want to make a main URL and that URL will be the main route for all my Django apps.
Suppose I have 3 apps: blog, linux and business. I want to make URLs like this:
127.0.0.1:8000/blog/ (when i will click blog menu)
127.0.0.1:8000/blog/linux ( when i will click linux menu)
127.0.0.1:8000/blog/business (when i will click business menu)
The blog app will be my index home page and all the apps' links will be like this. I don't want to import all of the views and models in the blog app. The project's structure will be the same and I don't want to change it.
All I want is to make blog common for all the apps. If I click a post on a linux page, the URL will be like this:
127.0.0.1:8000/blog/linux/post name
How can I do this?
This is my project's structure:
[]

You can write all the URLs into the urls.py in your project folder or you can make a urls.py in your apps folder. Maybe read this

After Creating the App in django project by following procedure in https://docs.djangoproject.com/en/3.0/intro/tutorial01/
App Folder (blog app folder, found inside project folder)
Add these urls
127.0.0.1:8000/blog/linux
127.0.0.1:8000/blog/business
to the app/urls.py file above the admin.site url path
Project Folder:
Configure the urls.py file in the project folder by adding the 127.0.0.1:8000/blog/ url above the admin.site url path. This configuration is done to load this url when the server starts running.
The django checks for the requested url pattern and will route the first discovered url.
The django cannot identify duplicate url.

Related

Website is not loading styles and files because is loading a different path

I just published my web app which has the following structure:
Project Name
StylesFolder
filename.css
anotherfile.css
JavaScriptFolder
bootstrap.js
Index.html
What I did was:
Adding a new WebSite in the server IIS with the path were I publish my WebApp (ex. C:\WebProjects\PublishedApp\Project Portal)
Selecting my published app and converting into an application (The alias name was Project Name and the physical path was C:\WebProjects\PublishedApp\Project Portal\Project Name)
The problem is when I try to see the website. I'm able to enter to 192.169.100.20:80/Project%Name/ and my index page is loaded (I can see the text, inputs, etc.) but I cannot see any stlye and javascript input and when I check the console logs all the files are getting a 404 error response.
When I check which URL is used by the files I can see that they are trying to get accessed by 192.169.100.20:80/Project Name/StylesFolder/filename.css etc...
So my question is what can I do to remove the /Project%Name/ string from the URL?
PD. I'm using IIS 7
When you add your website in IIS, select the application folder you published. For example, when you publish your application to D:\Program Files\Publish Folder, select the Publish Folder folder directly when adding the website and choose the physical path.
This is the reference:Deploy Website on IIS

Non-english url path

In next.js that uses php-like approach - files in pages folder became url paths. Like /pages/reader.js will be loaded by url http://localhost/reader.
Problem is that i can't undersand how to use non-english url path in next.js?
Codesandbox example. (Update page to load from server)
Url example:
http://localhost/читатель
That changes internally by chrome to:
http://localhost/%D1%87%D0%B8%D1%82%D0%B0%D1%82%D0%B5%D0%BB%D1%8C
In next.js pages folder file named:
pages/читатель.tsx // not working
pages/%D1%87%D0%B8%D1%82%D0%B0%D1%82%D0%B5%D0%BB%D1%8C.tsx //working but i can't name files like that, i will not find what i need later.
Maybe php users resolved this somehow ;)
try to use encodeURI() of core javascript which can convert the specific characters to the required url form
const url=encodeURI('читатель.tsx');
console.log(url);//%D1%87%D0%B8%D1%82%D0%B0%D1%82%D0%B5%D0%BB%D1%8C.tsx
Then we can use this path to navigate

Securing files in Google Cloud app engine (NodeJS)

I have created a small web application with NodeJS Express. Basically a webserver that has a 'webserver.properties' file. With a very basic app.yaml file.
After deploying it to Google Cloud by use of 'gcloud app deploy' I get the everything up and running.
However...when I open the following URL in the browser: https://webserverurl.com/webserver.properties , the webserver.properties file can be approached and is in turn downloaded immediately.
How can I prevent this from happening and make sure that such properties files are inaccessible from outside?
The problem is that when you use this line:
app.use('/', express.static(__dirname + '/'));
you are giving access to your root directory. See this for a definition of __dirname. If you want to give access to a specific folder you can do this:
Lets say your root directory is src and you fave a dir with static files called src/myfiles. In order to give acces to files in myfiles you can use this line:
app.use('/mypathname', express.static('myfiles'));
where:
'/mypathname' is the part pertaining your URL. In your case it would be https://webserverurl.com/mypathname/any-file-name.jpg
express.static('myfiles') is the name of your local dir.
See this guide.
Hope this helps

Can't establish the URL of Bot Builder files stored in Azure App Service

I am developing a chatbot using NodeJS and BotBuilder. I have the file chatbot.jpg stored in a folder named image. This sits just beneath the root directory. I am able to display the image (using Kudu to find the URL) in a web browser as follows:
https://mysite.scm.azurewebsites.net/api/vfs/site/wwwroot/images/chatbot.jpg
If I remove the .scm element within the URL, I can no longer display the image.
Even more curiously, if I use the above URL in my bot code, the image doesn't display.
var welcomeCard = new builder.HeroCard(session)
.title("This is the new")
.subtitle('Virtual Assistant')
.images([
new builder.CardImage(session)
.url("http://mysite.scm.azurewebsites.net/api/vfs/site/wwwroot/images/chatbot.jpg")
alt("Virtual Assistant")
]);
session.send(new builder.Message(session)
.addAttachment(welcomeCard));
My question is, how do I find out the regular URL of the image stored in the Azure App Service, so that I can use it in my code?
From the public web, the URL should be https://mysite.azurewebsites.net/images/chatbot.jpg
The wwwroot folder is the root folder served by the app service.
Your code can't just the scm URL as that URL requires you to be logged in to the Azure portal; it's an admin URL.
To accomplish your goal, you need to configure your Restify server to serve static files.
Example Restify config (add to your bot code):
server.get(/\/images\/?.*/, restify.serveStatic({
directory: './images'
}));

Is it possible to change default sharepoint 2013 app url

The default app url looks like http://[app prefix]-[app id].[domain name]/[site collection path]/[app path]/pages/default.aspx.
It is unconvinient because every deployment during development generates new url. And after development stage the end users need a permanent link to the application, but every bug fixes or updates that will be deployed will cause new app url generation. Is there right way to fix the app url?
You can create a URL controller:
Create a list that would contain two fields: fakeUrl, realUrl,
fakeUrl can be something like "http://staticappname.[domain name]/[site collection path]/[app path]/pages/default.aspx"
realUrl would be your http://[app prefix]-[app id].[domain name]/[site collection path]/[app path]/pages/default.aspx
Give your users fakeUrl
Create a HTTPModule that would read the list and redirect the http request to the realUrl
After you redeploy your app, just change the realUrl in the list
***I'm not if this is your case but you could change your app to be a provider-hosted. Then you would get a static Url
You can open your SharePoint hosted add-in using an alternate link like:
http://[SharePointSite]/[Add-inName]
For eg.
http://contoso.com/sharepointhostedapp/

Resources