how to connect a python code to the server? - django-models

I have a function in my views.py that print a string. I have run the local server by django.
I wrote this code.The page of this project must show word "hello world" , but it doesn't!
Will you help me fix it?
from django.conf.urls.defaults import *
from mysite.views import hello
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
('^hello/$', hello),
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)

Judging by what you have and receiving 404 not found I presume you are just going to localhost:8000
However your url setup says that you should go to localhost:8000/hello/ (you have no page set for the index pattern url(r'^$', hello) )
You also need to follow the correct syntax in your URLs. You currently have:
('^hello/$', hello),
You need to have:
url(r'^hello/$', hello),
You can also enable more verbose debugging by going to your settings.py file and setting DEBUG = True

Related

Wagtail 2.2 references API v1

I've just upgraded to Wagtail 2.2 and I'm getting an error 'wagtailadmin_api_v1 is not a registered namespace'. Part of the upgrade moved to api_v2 (which is in my INSTALLED_APPS). I did a search of the Wagtail code and found references to api_v1 in wagtail.admin.api.urls and wagtail/admin/templates/wagtailadmin/admin_base.html (there were several others in tests). I changed the references to V2, but then got the same error claiming that 'wagtail_api_v2 is not a registered namespace.
My question is whether anyone else has seen a similar problem and second, should there be any references to api_v1 in Wagtail 2.2
I was having the same error while integrating Wagtail 2.5 to an existing Django 2.2 project. My mistake was including Wagtail's urls to a namespaced urls.py.
The wagtailadmin_api_v1 is set on wagtail/admin/api/urls.py
According to the docs for url-configuration , you must include those patterns on your main urls.py.
~/projects/project_name/
manage.py
project_name/
my_app/
models.py
urls.py # Those are app-specific urls
views.py
__init__.py
...
settings.py
urls.py # This is the urls.py you should modify
wsgi.py
__init__.py
...
Pattern to be included:
from django.urls import path, re_path, include
from wagtail.admin import urls as wagtailadmin_urls
from wagtail.documents import urls as wagtaildocs_urls
from wagtail.core import urls as wagtail_urls
urlpatterns = [
...
re_path(r'^cms/', include(wagtailadmin_urls)),
re_path(r'^documents/', include(wagtaildocs_urls)),
re_path(r'^pages/', include(wagtail_urls)),
...
]
Be sure to include those patterns on your main urls.py (it shouldn't set an app_name variable, or all the patterns will be automatically namespaced.)
Stumbled over the same issue today and this worked for me:
# api views.py
from wagtail.api.v2.router import WagtailAPIRouter
from wagtail.api.v2.views import PagesAPIViewSet
wagtail_api_router = WagtailAPIRouter("cast:api:wagtail")
wagtail_api_router.register_endpoint("pages", PagesAPIViewSet)
# local urls.py
app_name = "api"
urlpatterns = [
...,
# wagtail api
path("wagtail/", include((views.wagtail_api_router.get_urlpatterns(), "api"), namespace="wagtail")),
]
Reverse looks now like this:
reverse("cast:api:wagtail:pages:listing")

AngularJS Error using manifest.appcache

Case 1: After event 'cached' comming from window.applicationCache.addEventListener, i get my mobile using OFFLINE MODE(airplane mode i mean),then i open my webapp from HomeScreen icon and everything works fine, except AngularJS, that doesnt get loaded. None function or variable is recnognized.
Case 2: After event 'cached' comming from window.applicationCache.addEventListener, i open my webapp from HomeScreen icon using ONLINE MODE, at this moment angular worked fine because its on correct view. BUT if i dont interact with webApp (Login for example), when i get offline mode, AngularJs get a error and not even the correct view is displayed anymore.
EDIT: I realized that if after cached event, i close web app, and then open it again, without interact, it will work fine in offline mode... How is it possible?
All the calls to Angular scripts are getting called from same page that im using <html manifest="manifest.appcache" type="text/cache-manifest">, why it wont work just after i send it to home screen?
I already tried couple workarounds.. none work!
Any help is appreciated
Above my manifest code:
CACHE MANIFEST
# Learn more:
# https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache
# -----------------------------------------------------------------------------
# It's necessary to tell web browsers to reconsider this manifest any time the
# website is updated, and you do so by changing *anything* inside the manifest.
# A common way to do this is by simply updating a commented-out string, like a
# date or a version number, or both:
# 2016-09-10:v1.122
# -----------------------------------------------------------------------------
# This is where you define all of the resources to be cached. Add new and/or
# remove old resourses as needed, keeping each one on its own line. Learn more:
# https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache#Explicit_entries
CACHE:
assets\js\jquery.min.js
assets\js\main.js
assets\js\skel.min.js
assets\js\util.js
assets\js\ie\html5shiv.js
assets\js\ie\respond.min.js
js\angular.min.js
js\angular-cookies.min.js
js\app\gmApp-controller.js
js\app\gmApp-factory.js
LICENSE.txt
assets\css\ie8.css
assets\css\ie9.css
assets\css\main.css
assets\fonts\FontAwesome.otf
assets\fonts\fontawesome-webfont.eot
assets\fonts\fontawesome-webfont.svg
assets\fonts\fontawesome-webfont.ttf
assets\fonts\fontawesome-webfont.woff
assets\fonts\fontawesome-webfont.woff2
assets\css\font-awesome.min.css
images\02.png
images\avatar.jpg
images\bg_login.jpg
images\favicon.png
images\fundo-bar.jpg
images\fundo-home.jpg
images\hotel-1.png
images\logo.jpg
images\pic01.jpg
images\pic02.jpg
images\pic03.jpg
images\pic04.jpg
images\pic05.jpg
images\pic06.jpg
images\pic07.jpg
images\pic08.jpg
images\pic09.jpg
images\pic10.jpg
images\pic11.jpg
images\pic12.jpg
images\cancun\chichen-tza.jpg
images\cancun\cirque-soleil.jpg
images\cancun\coco-bongo.jpg
images\cancun\haceienta-mortero.jpg
images\cancun\isla-mujeres.jpg
images\cancun\la-isla-shopping.jpg
images\cancun\navio-pirata.jpg
images\cancun\shopong-plaza.jpg
images\cancun\tulum.jpg
images\cancun\xcaret.jpg
images\cancun\xel-ha.jpg
images\dicas\dica1.jpg
images\dicas\dica2.png
images\dicas\dica3.jpg
images\dicas\dica3a.jpg
images\dicas\dica3b.jpg
images\dicas\dica3c.jpg
images\dicas\dica3d.jpg
images\dicas\dica3e.jpg
images\dicas\dica4.jpg
images\dicas\dica5.jpg
images\dicas\dica6.jpg
images\dicas\dica6a.jpg
images\dicas\dica6b.jpg
images\dicas\dica6c.jpg
images\dicas\dica7.jpg
images\dicas\dica7a.jpg
images\dicas\dica7b.jpg
images\dicas\dica7c.jpg
images\dicas\dica9.jpg
images\dicas\rodape.jpg
images\mini-menu\Cancun-42.jpg
images\mini-menu\chichen-tza.jpg
images\mini-menu\cirque-soleil.jpg
images\mini-menu\coco-bongo.jpg
images\mini-menu\haceienta-mortero.jpg
images\mini-menu\isla-mujeres.jpg
images\mini-menu\la-isla-shopping.jpg
images\mini-menu\navio-pirata.jpg
images\mini-menu\shopong-plaza.jpg
images\mini-menu\tulum.jpg
images\mini-menu\xcaret.jpg
images\mini-menu\xel-ha.jpg
index.html
# -----------------------------------------------------------------------------
# Resources that must be retrieved from the network. The wild card ensures any
# resource not listed in the cache above will instead be downloaded from the
# network. Learn more:
# https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache#Network_entries
NETWORK:
*
# -----------------------------------------------------------------------------
# Fallbacks. In each row, if the first resource isn't available, the second
# resource is requested. Uncomment and update as needed. Learn more:
# https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache#Fallback_entries
FALLBACK:
assets\fonts\FontAwesome.otf assets\fonts\FontAwesome.otf
assets\fonts\fontawesome-webfont.eot assets\fonts\fontawesome-webfont.eot
assets\fonts\fontawesome-webfont.svg assets\fonts\fontawesome-webfont.svg
assets\fonts\fontawesome-webfont.ttf assets\fonts\fontawesome-webfont.ttf
assets\fonts\fontawesome-webfont.woff assets\fonts\fontawesome-webfont.woff
assets\fonts\fontawesome-webfont.woff2 assets\fonts\fontawesome-webfont.woff2
js\angular.min.js js\angular.min.js
js\angular-cookies.min.js js\angular-cookies.min.js
Detail: all these fallback links are already 'work-arounds' im trying to get everything works fine at 'Add to home screen' event
After a while i realized that it was a css reference inside .css files. After add that references into manifest everything works like a charm

erreur cache with external parameters

i would like to use external parameters to config my parameters.yml.
so i follow this tutorial :
http://symfony.com/doc/current/cookbook/configuration/external_parameters.html
in my parameters.yml i have put this :
parameters:
database_host: localhost
database_port: null
database_name: '%database.name%'
database_user: '%database.user%'
database_password: '%database.pass%'
mailer_transport: smtp
mailer_host: localhost
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt
it works when i run my website with this parameters except when i clear the cache with command line.
i got this error :
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "database.name". Did you mean this: "database_name"?
Do you know the solution to resolve this problem.
thank you for your help
First create a php file and the logica, then import the php file to the config.yml and after comment the variables in parameters file. Have you tried to do something like this?
# parameters.php
$container->setParameter('database_name', $databaseName);
# app/config/config.yml
imports:
- { resource: parameters.php }
# app/config/parameters.yml
#database_name: '%database.name%'
#database_user: '%database.user%'

Gitlab Active Directory issues - gitlab-7.7.1_omnibus

I am having issues with Active Directory authentication via LDAP on Gitlab omnibus. I have tested the credentials and bind dn using ldapsearch and received a response with no issues, but for some reason I am not seeing any attempts at connecting when I login as an AD user on the gitlab frontend. I receive the error "Could not authorize you from Ldapmain because "Invalid credentials"." no matter if I'm using valid credentials or not.
I also receive the following from sudo gitlab-rake gitlab:check:
** Invoke gitlab:ldap:check (first_time)
** Invoke environment
** Execute gitlab:ldap:check
Checking LDAP ...
LDAP users with access to your GitLab server (only showing the first 100 results)
Server: ldapmain
Checking LDAP ... Finished
Please let me know if my explanation is not clear, or if you think that additional information would be helpful. I tried searching around and am not finding my exact issue.
My configuration is as follows:
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-EOS # remember to close this block with 'EOS' below
main: # 'main' is the GitLab 'provider ID' of this LDAP server
## label
#
# A human-friendly name for your LDAP server. It is OK to change the label later,
# for instance if you find out it is too large to fit on the web page.
#
# Example: 'Paris' or 'Acme, Ltd.'
label: 'LDAP'
host: 'myadserver.my.domain.net'
port: 389
uid: 'sAMAccountName'
method: 'plain' # "tls" or "ssl" or "plain"
bind_dn: 'CN=Gitlab,OU=Service Accounts,OU=Washington\, D.C.,OU=United States,OU=NA,DC=my,DC=domain,DC=net'
password: 'mypasswrd'
# This setting specifies if LDAP server is Active Directory LDAP server.
# For non AD servers it skips the AD specific queries.
# If your LDAP server is not AD, set this to false.
active_directory: true
# If allow_username_or_email_login is enabled, GitLab will ignore everything
# after the first '#' in the LDAP username submitted by the user on login.
#
# Example:
# - the user enters 'jane.doe#example.com' and 'p#ssw0rd' as LDAP credentials;
# - GitLab queries the LDAP server with 'jane.doe' and 'p#ssw0rd'.
#
# If you are using "uid: 'userPrincipalName'" on ActiveDirectory you need to
# disable this setting, because the userPrincipalName contains an '#'.
allow_username_or_email_login: true
# Base where we can search for users
#
# Ex. ou=People,dc=gitlab,dc=example
#
base: 'OU=Washington\, D.C.,OU=United States,OU=NA,DC=my,DC=domain,DC=net'
# Filter LDAP users
#
# Format: RFC 4515 http://tools.ietf.org/search/rfc4515
# Ex. (employeeType=developer)
#
# Note: GitLab does not support omniauth-ldap's custom filter syntax.
#
#user_filter: ''
EOS
This was, of course, a whitespace issue. See lines below:
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-EOS # remember to close this block with 'EOS' below
main: # 'main' is the GitLab 'provider ID' of this LDAP server
## label
#
# A human-friendly name for your LDAP server. It is OK to change the label later,
# for instance if you find out it is too large to fit on the web page.
#
# Example: 'Paris' or 'Acme, Ltd.'
label: 'LDAP'

Catch All Script in App Engine Python (APP.YAML) does not work in Static Files

I have tried everything but it seems that you cannot get a catch all url...
- url: /.*
script: not_found.py
...to work on urls that are based on static directory paths. eg. I can type in www.foobar.com/asdas/asd/asd/asd/ad/sa/das/d and I can get a nice custom 404 page. But if I alter a static path url like www.foobar.com/mydir/mydir/mypage.html, I just get the horrible generic 404....
Error: Not Found
The requested URL /mydir/mydir/mypage.html was not found on this server.
... I would like to alter whatever catches the url in directory paths and writes the 404. This appears the only way to get a consistent custom 404 page in GAE Python.
Can anyone help? I have written my website from scratch and have a very limited knowledge of Python. Achieving a consistent custom 404 is the only thing I cannot seem to overcome.
EDIT/ADD : OK I've added the kind suggestion of #Lipis , and gone through getting started which which thankfully has given me a much better understanding of classes (I sadly can't vote it up yet). But! I am using a .py script found on the net and I think the NotFound class is interfering with the class that gives my index page, because now my index page is the 404 page specified by the Jinja! I have very little understanding of MainHandler so I may have to give up for now.
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
import jinja2
class MainHandler(webapp.RequestHandler):
def get (self, q):
if q is None:
q = 'index.html'
path = os.path.join (os.path.dirname (__file__), q)
self.response.headers ['Content-Type'] = 'text/html'
self.response.out.write (template.render (path, {}))
class NotFound(webapp.RequestHandler):
def post(self):
# you need to create the not_found.html file
# check Using Templates from Getting Started for more
jinja_environment = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
template = jinja_environment.get_template('404.html')
self.response.out.write(template.render(template_values))
def main ():
application = webapp.WSGIApplication ([('/(.*html)?', MainHandler),('/.*', NotFound)],
debug=True)
util.run_wsgi_app (application)
if __name__ == '__main__':
main ()
For better understanding I'll make some modifications on the Getting Started example which I assume that you have done it and you made some experiments with it.
It's not a good idea to have the static file for all the not found pages in the app.yaml since most likely you would like to show something more dynamic and usually the - url: /.* should be handled within your app.
In this example we are going to add a new RequestHandler for all your not found pages
import jinja2
import os
# more imports
jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
class MainPage(webapp2.RequestHandler):
def get(self):
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))
class NotFound(webapp.RequestHandler):
def get(self):
# you need to create the not_found.html file
# check Using Templates from Getting Started for more
template = jinja_environment.get_template('not_found.html')
self.response.out.write(template.render(template_values))
application = webapp.WSGIApplication(
[('/', MainPage),
('/.*', NotFound)], # <-- This line is important
debug=True)
But in order to make the jinja2 templates work, follow carefully the modifications that you need to do in Using Templates section from the Getting Started.
The order in the URL mapping is very important so this catch all regular expression (/.*) should be always the last one, because otherwise all the other rules will be skipped.
If you want to catch all URLs, you will have to modify your main request handler in your file "not_found.py" by adding '/.*'.
For example, you can set the file "not_found.py" to:
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainHandler(webapp.RequestHandler):
def get(self):
self.response.out.write("Hello, MAIN!")
application = webapp.WSGIApplication(
[('/.*', MainHandler)], # <--- Add '/.*' here
debug=True)
def main():
run_wsgi_app(application)
If you navigate to www.foobar.com/asd/ad/sa/das/d or any other URL, you will see the message "Hello, MAIN!.
Hope it helps. Ask question if needed

Resources