I am trying to refer to the WordPress blog through my sub domain. example -
blog.example.com
WordPress is hosted on GoDaddy
My main app (main domain) is on Django (hosted on Heroku). Have site maps set up on Django apps as well under:
example.com/site maps.xml
How do I integrate the two sitemaps so that when I go to example.com/site maps.xml I should see sitemaps from both? Is there a way?
Related
I´m currently working on an application: Django backend and angular frontend. Everything works fine, but after refreshing one page in the browser I don´t get the angular response anymore. But what I get is a successful answer from my Django server (HTTPResponse: 200).
My Django urls.py is as followed:
from django.urls import path
from quickstart import views
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [
path('images/', views.ImageList.as_view()),
path('images/<str:id>/', views.Image.as_view()),
path('images/<str:id>/explanations', views.Explanation.as_view())
]
My app-routing.modules.ts:
const routes: Routes = [
{path: 'home', component: MainComponent},
{path: 'images', component: ImageComponent, children: [
{
path:':id', component: ImageDetailComponent
}
]},
{path: '', redirectTo: '/home', pathMatch: 'full'},
];
#NgModule({
imports: [RouterModule.forRoot(
routes
)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Angular production build is served as a static file. it makes the api request to the backend server for the CRUD operations.
what you need to do is serve the static files in angular dist(most probably the index.html file in the dist folder) folder.
using some sort of routing in django (suggestion have a prefix for the API or web app for django to know what are you asking for. look at this)
or have a standalone service hosted some where to serve Angular site(have a look at this) and let angular handle the routing.
How would you access the Django authentication framework from a Flask app?
I have a Django app and Flask app running in parallel on a server. Both are hosted behind the same domain, but behind different paths, so they should be able to see each other's cookies.
I'm using Flask to run a simple API microservice, where using Django would be overkill. However, to prevent abuse, I still want Flask to check the request's cookies to see if they're from a user who's still authenticated in the Django application. I don't want to re-implement an authentication framework in Flask.
Access Django settings from inside Flask is relatively simple. I just put something like this at the top of my Flask script to set the path to my Django settings module:
sys.path.insert(0, <path to Django project>)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mydjangoproject.settings")
from django.conf import settings
However, I'm unsure how to update a Flask request handler to pull the correct cookies from a request and verify them with Django's authentication backend. How would I do this?
Digging through the Django interals for the session and authentication middleware, it looks like it's pretty easy to fed Flask's native request instance to them. This seems to do it for me:
from importlib import import_module
from django.conf import settings
from django.contrib.auth.middleware import get_user
engine = import_module(settings.SESSION_ENGINE)
SessionStore = engine.SessionStore
session_key = request.cookies.get(settings.SESSION_COOKIE_NAME)
request.session = SessionStore(session_key)
user = get_user(request)
print(user.is_authenticated)
I'm trying to set Facebook login and registration on my web page (localhost for now).
Installed allauth
Set settings.py
Created an facebook app
And now, when I click on http://127.0.0.1:8000/accounts/login/ facebook href, it returns this alert:
Can't Load URL: The domain of this URL isn't included in the app's
domains. To be able to load this URL, add all domains and subdomains
of your app to the App Domains field in your app settings.
According to sites, I've set domain name (in Django-admin Sites) to
localhost
What should I do to make it work?
I have fully created a Django website with python-social-auth for facebook authentication and have hosted it on heroku(free version). The problem however is,that my Facebook authentication,which was working perfectly locally,is not working and it throws an error as follows:-
Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
I have configured my facebook settings , wherein the site url is the one hosted on heroku (https://quiet-hamlet-3248.herokuapp.com/). Also,I haven't changed my API keys/secret.
Any help would be appreciated.
So I just figured it out.
As mentioned here , one needs to update his settings file to include the line SOCIAL_AUTH_REDIRECT_IS_HTTPS = True
This is because heroku fails to pass the headers required to identify the app.
I have a single Django app that handles two (or more) parts of site, for example an "admin" and an "api" sections of the site. I also have normal html pages for the rest of the site, where no Django is needed.
I want to have the static html site on the root of my site, and the Django app on some sub-locations, for example
www.example.com -> Apache static html site
www.example.com/admin/ -> Django app, serving the pages for the admin
www.example.com/api/ -> Django app, serving the pages for the api
At first I try to do so all form Django, using the urls like so:
# my_app/urls.py
...
url(r'^admin/', include('admin.urls')),
url(r'^api/', include('api.urls')),
url(r'^(?P<path>.*)$', ??????????),
...
But I couldn't figure out a good way to delegate the serving of those static pages to Apache. (It did work if I use url(r'^(?P<path>.*)$, 'django.views.static.serve', {'document_root': '/path/to/static/site'}), but the Django documentation forbids to use that on a production server.)
Then I tried with the apache configuration:
# httpd.conf
...
DocumentRoot /path/to/static/site
WSGIScriptAlias /admin /path/to/django/my_app/wsgi.py
WSGIScriptAlias /api /path/to/django/my_app/wsgi.py
...
This worked as far as requests to root returned the static site and requests to both "admin" and "api" would return the Django site, but within Django I found no way to distinguish if the request came from '/admin' or from '/api'. (Plus I'm not sure if having two WSGIScriptAlias pointing at the same wsgi might cause some problems.)
If someone knows of a way to achieve this without having to split my Django app into two (or more) parts it would be greatly appreciated.
I had the almost exact same problem. In Apaches virtual host config for the site use
WSGIScriptAliasMatch ^(/(admin|api)) /path/to/django/my_app/wsgi.py$1
instead of
WSGIScriptAlias /admin /path/to/django/my_app/wsgi.py
WSGIScriptAlias /api /path/to/django/my_app/wsgi.py
Check these Q&A for further information:
Django (wsgi) and Wordpress coexisting in Apache virtualhost
Reconfiguring Apache to serve website root from new php source and specific sub-urls from old django site