You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: FAQ.md
+26-6Lines changed: 26 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,13 @@ For more examples, check out Hug's [documentation](https://github.com/timothycro
6
6
7
7
Q: *Can I use Hug with a web framework -- Django for example?*
8
8
9
-
A: You can use Hug alongside Django or the web framework of your choice, but it does have drawbacks. You would need to run hug on a separate, hug-exclusive server. You can also [mount Hug as a WSGI app](https://pythonhosted.org/django-wsgi/embedded-apps.html), embedded within your normal Django app.
9
+
A: You can use Hug alongside Django or the web framework of your choice, but it does have drawbacks. You would need to run hug on a separate, hug-exclusive server. You can also [mount Hug as a WSGI app](https://pythonhosted.org/django-wsgi/embedded-apps.html), embedded within your normal Django app.
10
10
11
11
Q: *Is Hug compatabile with Python 2?*
12
12
13
-
A: Python 2 is not supported by Hug. However, if you need to account for backwards compatability, there are workarounds. For example, you can wrap the decorators:
13
+
A: Python 2 is not supported by Hug. However, if you need to account for backwards compatability, there are workarounds. For example, you can wrap the decorators:
14
14
15
-
```Python
15
+
```Python
16
16
defmy_get_fn(func, *args, **kwargs):
17
17
if'hug'inglobals():
18
18
return hug.get(func, *args, **kwargs)
@@ -29,7 +29,7 @@ Q: *How can I serve static files from a directory using Hug?*
29
29
30
30
A: For a static HTML page, you can just set the proper output format as: `output=hug.output_format.html`. To see other examples, check out the [html_serve](https://github.com/timothycrosley/hug/blob/develop/examples/html_serve.py) example, the [image_serve](https://github.com/timothycrosley/hug/blob/develop/examples/image_serve.py) example, and the more general [static_serve](https://github.com/timothycrosley/hug/blob/develop/examples/static_serve.py) example within `hug/examples`.
31
31
32
-
Most basic examples will use a format that looks something like this:
32
+
Most basic examples will use a format that looks something like this:
33
33
34
34
```Python
35
35
@hug.static('/static')
@@ -50,15 +50,15 @@ A: You can access a list of your routes by using the routes object on the HTTP A
50
50
51
51
`__hug_wsgi__.http.routes`
52
52
53
-
It will return to you a structure of "base_url -> url -> HTTP method -> Version -> Python Handler". Therefore, for example, if you have no base_url set and you want to see the list of all URLS, you could run:
53
+
It will return to you a structure of "base_url -> url -> HTTP method -> Version -> Python Handler". Therefore, for example, if you have no base_url set and you want to see the list of all URLS, you could run:
54
54
55
55
`__hug_wsgi__.http.routes[''].keys()`
56
56
57
57
Q: *How can I configure a unique 404 route?*
58
58
59
59
A: By default, Hug will call `documentation_404()` if no HTTP route is found. However, if you want to configure other options (such as routing to a directiory, or routing everything else to a landing page) you can use the `@hug.sink('/')` decorator to create a "catch-all" route:
60
60
61
-
```Python
61
+
```Python
62
62
import hug
63
63
64
64
@hug.sink('/all')
@@ -67,3 +67,23 @@ def my_sink(request):
67
67
```
68
68
69
69
For more information, check out the ROUTING.md file within the `hug/documentation` directory.
70
+
71
+
Q: *How can I enable CORS*
72
+
73
+
A: There are many solutions depending on the specifics of your application.
74
+
For most applications, you can use the included cors middleware:
[](https://gitter.im/timothycrosley/hug?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
10
10
11
-
NOTE: For more in-depth documentation visit [hug's website](http://www.hug.rest)
0 commit comments